ls command output required to a text file through VB6 code

Advertisement

sagar2885
Joined:
Posts:
4
Location:
Mumbai

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.

Reply with quote

Advertisement

Guest

Re: ls command output required to a text file through VB6 code

I had tried the xml logging also but it doesnt make any xml file. Below is the command:

sCommand = "C:\Program Files\WinSCP\winscp /command ""option batch off"" ""option confirm off"" ""open sftp://ftpuser:<password of server>@<IP address of server>"" ""ls"" /xmllog=""C:\test.xml"""

This doesnt work. Kindly help to rectify this, so that it makes some file.
Also I am not sure how easy it would be to read the xml file through VB6.

Following are the software details as required
WINSCP version used - WinSCP version 4.3.4(Build 1428)
Operating system (Client Machine) - MS Windows XP Professional Version 2002, SP3.
Transfer Protocol - SFTP-3.
SFTP Server details - Core FTP mini-SFTP-server
Language used for automation of file transfer - VB6 (We neither use console nor CMD Prompt for viewing output).


Regarding query 2:
I wanted to say, as u can see my code snippet in previous post, if suppose the server is down or pwd is given wrong, the shell command still gets executed, but the command line which we are passing doesnt as we purposely provided wrong pwd. But how can we know if the command line got executed as we dont use cmd prompt.

Reply with quote

sagar2885
Joined:
Posts:
4
Location:
Mumbai

XML logging in Winscp

Hi,

After long try on XML logging, finally i got it in latest release of Winscp. XML is created, however when I tried opening the file it gave me some error. When i check the xml by editing, i found xml tags were missing. There were no tags in file and hence it was throwing error while opening. I am not getting solution how to read output of ls command. As if i try to generated .log file, an unstructured file is generated . Please help me to resolve the issue. This is very urgent as i have client delivery this wednesday.

Reply with quote

Advertisement

sagar2885
Joined:
Posts:
4
Location:
Mumbai

I tried with the latest beta version of winscp, so the xml file got generated & I was able to open it. But not sure if our client agrees to using of Beta version!! Would like to know, when will this latest beta version become official? Also is there any alternative to XML logging as we need to read the names of files present on server through VB6 code itself,take the names into collection, run some validationand only then download files from server.

Regarding my query2, you had posted to check exit code 1 or 0, but my question is how can we do that? As we dont use cmd prompt at all, pass all command lines through shell in VB6.

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,517
Location:
Prague, Czechia

[quote="sagar2885"]I tried with the latest beta version of winscp, so the xml file got generated & I was able to open it. But not sure if our client agrees to using of Beta version!! Would like to know, when will this latest beta version become official?[quote]
Still few months to go.

Regarding my query2, you had posted to check exit code 1 or 0, but my question is how can we do that? As we dont use cmd prompt at all, pass all command lines through shell in VB6.
Well I do not know VB6, but there has to be a way.

Reply with quote

Advertisement

You can post new topics in this forum