ls command output required to a text file through VB6 code
Query 1:-
In order to transfer files via WinSCP from one location to another, we need to save the names of the files that are present on the remote server to a text file, through shell command. We are currently using 'ls' command for this activity. As our ultimate aim is to read the text file through VB6 and take all the names into collection.
Here is the code snippet of VB6:-
Dim sCommand As String
Dim dretval As Double
sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuser:<password of server>@<IP address of server>"" ""get /ncbout/ /abcd/"" ""cd /ncbout/"" ""rm ABCD.INI""
dretval = Shell(sCommand)
The above code works fine when executed in VB6.
NOTE: We are not using BAT file to execute our code, as we want to save on time, as there are millions of files to be transferred.
In order to log the output of 'ls' command we used following command in VB6. The same is working fine:-
sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuser:<password of server>@<IP address of server>"" ""ls"" /log=""C:\test.log"""
However, the issue is, above command gives unstructured output in test.log. This makes it difficult to read the log file through code as we only require the names of file that are present on server.
To achieve the above mentioned requirement {taking only names of files from log} we executed below command on command prompt and it produced the desired result:
C:\Program Files\WinSCP>winscp /command "option batch off" "option confirm off" "open sftp://ftpuser:password of server>@<IP address of server>" "ls" | find "." > test.txt
Issue here is we are not using Command prompt in our application and we want it to be done through VB6 code.
For your reference we tried below command in VB6 which doesnt provide us any output:
sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuserpassword of server>@<IP address of server>"" ""ls"" | find ""."" > test.txt"
Also if possible we require only the names of the files present on server path and we dont require any other details like Date modified, size etc.
Note: Other Commands like "put", "get", "rm" works fine through VB6 for us. Request you to provide solution for "ls" command for the reason mentioned earlier.
Query 2:-
We use SHELL command to execute the command line. In case server is down or incorrect login details are provided, this SHELL command still gets executed and gives random numeric values making it difficult to find whether our command line got executed or no through Shell. Please let us know how we can get these details from VB6 code itself. This is required for Error handling purpose.
We have already checked almost all the comments posted in forum related to above queries; however couldn't find desired results.
Thanking you in anticipation!!
I am going to email to Martin as well.
In order to transfer files via WinSCP from one location to another, we need to save the names of the files that are present on the remote server to a text file, through shell command. We are currently using 'ls' command for this activity. As our ultimate aim is to read the text file through VB6 and take all the names into collection.
Here is the code snippet of VB6:-
Dim sCommand As String
Dim dretval As Double
sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuser:<password of server>@<IP address of server>"" ""get /ncbout/ /abcd/"" ""cd /ncbout/"" ""rm ABCD.INI""
dretval = Shell(sCommand)
The above code works fine when executed in VB6.
NOTE: We are not using BAT file to execute our code, as we want to save on time, as there are millions of files to be transferred.
In order to log the output of 'ls' command we used following command in VB6. The same is working fine:-
sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuser:<password of server>@<IP address of server>"" ""ls"" /log=""C:\test.log"""
However, the issue is, above command gives unstructured output in test.log. This makes it difficult to read the log file through code as we only require the names of file that are present on server.
To achieve the above mentioned requirement {taking only names of files from log} we executed below command on command prompt and it produced the desired result:
C:\Program Files\WinSCP>winscp /command "option batch off" "option confirm off" "open sftp://ftpuser:password of server>@<IP address of server>" "ls" | find "." > test.txt
Issue here is we are not using Command prompt in our application and we want it to be done through VB6 code.
For your reference we tried below command in VB6 which doesnt provide us any output:
sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuserpassword of server>@<IP address of server>"" ""ls"" | find ""."" > test.txt"
Also if possible we require only the names of the files present on server path and we dont require any other details like Date modified, size etc.
Note: Other Commands like "put", "get", "rm" works fine through VB6 for us. Request you to provide solution for "ls" command for the reason mentioned earlier.
Query 2:-
We use SHELL command to execute the command line. In case server is down or incorrect login details are provided, this SHELL command still gets executed and gives random numeric values making it difficult to find whether our command line got executed or no through Shell. Please let us know how we can get these details from VB6 code itself. This is required for Error handling purpose.
We have already checked almost all the comments posted in forum related to above queries; however couldn't find desired results.
Thanking you in anticipation!!
I am going to email to Martin as well.