In VB6, using the FilesSystemObject, how to access directories on multiple servers? - server

In a project we have a table with the following fields: FolderPath, FileType, DaysToKeep, ServerIP.
When the utility is executed, I read the rs from the table then want to access the [ServerIP]\[FolderPath] to see of the delta of Now() and the first file's (or a file's) last save date is greater than DaysToKeep.
I have most of the pseudo-code done and am confident in being able to do this on a local server using the FileSystemObject (importing Microsoft Scripting Runtime).
rsDirectoryList.MoveFirst
Do While Not rsDirectoryList.EOF
' Fields: FolderPath, FileType, DaysToKeep, ServerIP
Debug.Print "Values: " & rsDirectory.Fields("FolderPath").Value
' get directory contents from [ServerIP]:[FolderPath]
'fileSpec = rsDirectory.Fields("ServerIP") & rsDirectory.Fields("FolderPath")
Set f = fso.GetFile(fileSpec)
Debug.Print "Last Modified: " & f.DateLastModified & vbNewLine
' Get the date of the first file from [ServerIP]\[FolderPath]
' If Now() - FileDate in days > DaysToKeep, purge directory
'If DateDiff("d", Now(), f.DateLastModified) > rsDirectory.Fields("DaysToKeep").Value Then
' ' Delete files from specified directory
' Kill (serverIP \ FolderPath) ?????
'Else
' Debug.Print "Skipping: " & rsDirectory.Fields(0).Value & vbNewLine
'End If
rs1.MoveNext
Loop
I was thinking that I may have to create a share for each server on the utility's server and access them by drive letter, rather than by IP address.
Is there a way to do this with the given IP addresses?

Related

Where exactly do we place this postgresql.conf configuration file in spring boot application?

I am trying to encrypt a column in my prostrgres DB. The column name is "test" of type "bytea".
My enity code is below,
#ColumnTransformer(read = "pgp_sym_decrypt(" + " test, "
+ " current_setting('encrypt.key')"
+ ")", write = "pgp_sym_encrypt( " + " ?, "
+ " current_setting('encrypt.key')" + ") ")
#Column(columnDefinition = "bytea")
private String test;
postgresql.conf configuration file:
encrypt.key = 'Wow! So much security.
Placed the postgresql.conf configuration file in src/main/resources of spring boot appln. But the encryption.key value is not being picked up. And is there a way to pass the key using application.properties?
postgresql.conf is the configuration file for the Postgres server. It's stored inside the data directory (aka "cluster") on the server.
You can't put it on the client side (where your application runs). It has no meaning there.
To change values in there, you need to edit the file (on the server) or use ALTER SYSTEM.
If you want to change a configuration setting for the current session, use SET or set_config()
The latter two are probably the ones you are looking for to initialize the custom property for your encryption/decryption functions.
The way to use encrypt.key, not only for current session, it's store it in postgresql.conf.
The correct place is at the end of this file, in the "Customized Options" section:
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------
# Add settings for extensions here
encrypt.key=123456
Reload the configuration of the database server:
systemctl reload postgresql.service
To testing if it's working correctly. Open a pgsql session and type:
mydb=# show encrypt.key;
encrypt.key
-------------
123456
(1 row)
Example of encrypt:
mydb=# select pgp_sym_encrypt('Hola mundo',current_setting('encrypt.key'));
pgp_sym_encrypt
------------------------------------------------------------------------------------------------------------------------------------------------------------
\xc30d04070302255230e388dfe25e7dd23b01c5b8e62d148088a3417d3c27ed2cc11655d863b271672b9f076fffb82f1a7f074f2ecbe973df04642cd7a4f76ca5cff4a13b9a71e7cc6e693827
(1 row)
Example of decrypt:
mydb=# select pgp_sym_decrypt('\xc30d04070302255230e388dfe25e7dd23b01c5b8e62d148088a3417d3c27ed2cc11655d863b271672b9f076fffb82f1a7f074f2ecbe973df04642cd7a4f76ca5cff4a13b9a71e7cc6e693827',current_setting('encrypt.key'));
pgp_sym_decrypt
-----------------
Hola mundo
(1 row)

Using FTP commands to download a file with sockets

I'm using a proprietary programming language and it has no built in FTP function. Therefore I'm using sockets.
sHandle := SocketOpen('ftp.stackoverflow.net', 21);
SocketReadString(sHandle, answer);
retW := SocketWriteString(sHandle, 'user user1673665' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
retW := SocketWriteString(sHandle, 'pass !##$%^&*' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
retW := SocketWriteString(sHandle, 'cwd update' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
retW := SocketWriteString(sHandle, 'retr update.txt' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
SocketClose(sHandle);
These are the answers I receive from the FTP server:
220-Welcome to stackoverflow FTP
220 Unauthorized access is illegal!
331 Password required for user1673665
230 Logged on
250 CWD successful. "/update" is current directory.
But why do I get after retr update.txt this error:
503 Bad sequence of commands.
I'm debugging throught the code step by step. Therefore response time should not be the problem.
The RETR command has to be preceded at least by PASV or PORT to setup a data connection.
Consult RFC 959, particularly the section "3.2. Establishing data connections"
When using the PASV, you have to open a connection the port that the server returned in the 227 response.
Also note that the FTP commands shall be sent in uppercase.
Thanks Martin Prikryl and Steffen Ullrich for your help. I'll add the working code here with comments. Maybe it will be useful for someone. Maybe it's necessary to add sleep commands because the code runs faster than the server responds.
# Open control channel
sHandle := SocketOpen('ftp.stackoverflow.net', 21);
SocketReadString(sHandle, answer);
SocketWriteString(sHandle, 'USER user1673665' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
SocketWriteString(sHandle, 'PASS !##$%^&*' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
SocketWriteString(sHandle, 'CWD update' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
# Enter passive mode and receive data channel adress and port
SocketWriteString(sHandle, 'PASV' & CHR(13) & CHR(10));
SocketReadString(sHandle, answer);
# Create adress for data channel
IF answer <> NOVALUE THEN
# Split answer on character , and ( and ) and whitespace
retPASV[] := StrSplit(answer, ',() ');
ENDIF;
CASE retPASV[1]
# Passive mode is 227
IS = 227 DO
connect := retPASV[6] & '.' & retPASV[7] & '.' & retPASV[8] & '.' & retPASV[9];
IS DO
ENDCASE;
# Create port for data channel
# Port is secondlast number * 256 + last number from PASV reply
port := String2Num(retPASV[10]) * 256 + String2Num(retPASV[11]);
# Open data channel on sHandle2
sHandle2 := SocketOpen(connect, port);
SocketReadString(sHandle2, answer2);
# Download file on control channel
SocketWriteString(sHandle, 'RETR update.txt' & CHR(13) & CHR(10));
SocketReadString(sHandle, Antwort);
# Read file on data channel - result of textfile in string answer2
SocketReadString(sHandle2, answer2);
SocketClose(sHandle);
Why does retr update.txt not work?
Because you are not following the specification of the FTP protocol. Transfer of data is done using a separate TCP connection which needs to be setup beforehand using PASV, EPSV, PORT or EPRT commands. For more information, see the standards (that's what they are for), i.e. RFC 959 and RFC 2428.

Error Running Bulk Metric create script in command manager Microstrategy

I'm trying to run the script below in the command manager, and I'm getting the error messages below. The script is supposed to bulk create a bunch of metrics from facts in another folder. Can someone please tell me what I'm missing. I'm new to running scripts in command manager.
Script:
//list all metrics in the project
String sProjectName = "ProjectName";
String sFactFolder = "\Schema Objects\Facts\FolderName";
String sMetricFolder = "\Public Objects\Metrics\BulkTest";
ResultSet oFacts = executeCapture("LIST ALL FACTS IN FOLDER '" + sFactFolder + "' FOR PROJECT '" + sProjectName + "';");
oFacts.moveFirst();
while (!oFacts.isEof() )
{
//get name and path of this metric to list properties
String sFactName = oFacts.getFieldValueString(DisplayPropertyEnum.NAME);
//get properties of each metric
EXECUTE("CREATE METRIC "" + sFactName + "" IN FOLDER "" + sMetricFolder + "" EXPRESSION 'sum([" + sFactName + "])' ON PROJECT "" + sProjectName + "";");
oFacts.moveNext();
}
Errors:
Syntax error at line '2', column '4'. Expected: ADD, ALTER, APPLY, APPEND, ACTIVATE, BULKSAVEBEGINS, BULKSAVEENDS, CLEAR, CONNECT, CREATE, DEACTIVATE, DELETE, DISCONNECT, DISABLE, ENABLE, GET, GRANT, IDLE, IMPORT, INVALIDATE, KILL, LIST, LOAD, LOG, PUBLISH, PURGE, REGISTER, REMOVE, REPLACE, RESTART, RESUME, REVOKE, RUN, SEND, SET, START, STOP, TAKE OWNERSHIP, TRIGGER, UNLOAD, UNLOCK, UNREGISTER, UPDATE, VALIDATE, RESET, LOCK, EXECUTE, EXPIRE
Task(s) execution completed with errors.
Execution Time: 00:00:00
If you’re running that directly in Command Manager, it will fail, because it’s Java. You’ll need to create a procedure with that code, and call the procedure from Command Manager. The documentation should cover that process I think.
Use Procedure and type (do not paste the code) that code in there.
Also, change the Execute command as below.
EXECUTE("CREATE METRIC '" + sFactName +
"' IN FOLDER '" + sMetricFolder +
"' EXPRESSION 'sum([" + sFactName + "])' ON PROJECT '" + sProjectName + "';");
oFacts.moveNext();
It works.

Status for connector session is: 1544 Message: Code # 0 Connector Message: Error: Cannot find Connector 'DB2'

I have a database with two agents, well there are really more than two, but two that matter right now. One works, the other does not. Both have Uselsx '*lsxlc' defined in (Options).
I have commented out everything in the failing agent except
Dim s As New NotesSession
Dim db As NotesDatabase
Dim agentLog As NotesLog
Set db = s.CurrentDatabase
'agent log
Set agentLog = New NotesLog("Customers from Aging Report - AKM")
Call agentLog.OpenNotesLog( db.server, "agentinfo.nsf" )
agentLog.LogActions = True 'Set to True/False to turn on/off action logging
agentLog.LogErrors = True 'Set to True/False to turn on/off error logging
Call agentLog.LogAction("Start Agent: GetCustomerDataBasedOnAging")
On Error Goto throwError
Dim lcses As New LCSession
Dim src As New LCConnection(COutConn)
%REM
....
%END REM
Exit Sub
throwError:
'Error code
Dim epos As String
Dim emsg As String
Dim msg As String
Dim result As String
Dim status As Integer
Dim msgcode As Long
If lcses.status <> LCSUCCESS Then
status = lcses.GetStatus (result, msgcode, msg)
Call agentLog.LogError( msgcode,"Status for connector session is: " & Cstr(status) & Chr(10) & "Message: " & msg & " Code # " & Cstr(msgcode) & Chr(10) & "Connector Message: " & result )
emsg = "Customers from Aging Report' Agent: ("+Cstr(Erl)+") "& "[" &Cstr(Err) & "] [" & Error$ & "]"
Call agentLog.LogError( Err, emsg)
Else
emsg = "Customers from Aging Report' Agent: ("+Cstr(Erl)+") "& "[" &Cstr(Err) & "] [" & Error$ & "]"
Call agentLog.LogError( Err, emsg)
End If
Resume Next
COutConn is defined as a constant with value 'DB2'
I get the following error in the agent log:
Status for connector session is: 1544
Message: Code # 0
Connector Message: Error: Cannot find Connector 'DB2'
This happens whether I use the constant COutConn, or "DB2".
The strange thing is that the other agent with the same definitions works properly. I know DB2 exists on the machine, it is i5/OS v5r4. DB2 is built in on this operating system.
What else do I need to look for?
The answer is, be sure you know which machine the agent is running on. When you right click the agent in Domino Designer, and select Run, as I did, the agent is not running on the server that the database resides on, but rather inside the Domino Designer client. that is going to be Windows or Linux depending on your workstation.
So why did the one agent work while the other did not? Well the one that worked was activated from a button in the Notes Client, and the function attached to the button used Run on Server. The server was indeed IBM i. However, in the case of the failing agent, I executed that one from within Domino Designer as mentioned above, thus no DB2 connector.
Here's to hoping someone can learn from my pain!

How do I get detailed PostgreSQL-errors in Access via ODBC?

Is there a way to get the detailed error-messages PostgreSQL shows when running a query from command-line or a client like PG-Admin when using the ODBC-Interface-Driver?
The Err-object in Access just tells you that something went wrong but is not very helpful - I have to run the same query again in PG-Admin to see where the problem is.
Silly me! Just have to iterate through the Errors-object...
Dim errX As DAO.Error
Dim strError As String
For Each errX In DAO.Errors
strError = strError & "# >> " & errX.number & " | txt >> " & _
errX.DESCRIPTION & Chr(10) & Chr(10)
Next errX