Issuing List command to remote directory and output to file

Advertisement

me119394
Joined:
Posts:
5
Location:
London

Issuing List command to remote directory and output to file

Hi,

I am trying to output the results of a list remote directory command to a text file but I'm getting an error
Too many parameters for command 'ls'
Here is the command line:
"C:\Program Files\Winscp\winscp.exe" /console /script=D:\FTP\listtest.txt
Here is the script:
option batch on
option confirm off
open BoxIT
ls /Home/boxit-BDOHR/Test >D:\FTP\lists.txt
ls /Home/boxit-BDOHR/Test2 >D:\FTP\lists2.txt
close
exit
After running the script I get following in console:
Too many parameters for command "ls".
If I run the command without the > string then it runs fine, is there a different notation for outputting the results to a file...?

Using WinSCP 4.2.5 on Windows XP.

Reply with quote

Advertisement

Guest

Re: Issuing List command to remote directory and output to file

Hi,

Thanks for the reply, I'm not conversant with xml and therefore do not know how to implement this even after going through the examples.

Could you provide a little more guidance on how to implement the xml logging and the elements based upon a ls command only wanting the filename & date & time....?

regards

Reply with quote

martin
Site Admin
martin avatar

Re: Issuing List command to remote directory and output to file

For examples, follow the links at the end of the article.

Reply with quote

me119394
Joined:
Posts:
5
Location:
London

Re: Issuing List command to remote directory and output to file

Would there be a possibility of this functionality being added in a future version as this would be very handy as an audit trail piece as well for confirmation that the files have reached their destination by attaching this file to an automated smtp email.

I've been trialing another FTP client called CoreFTP which has an output function and produces a log file of the transfer of files, I have pasted an example FYI.
2 1 20110406155516 20110406155516 "/Home/Boxit-BDOHR/Test/Brilo.txt" "D:\FTP\test\Brilo.txt"

2 1 20110406155516 20110406155516 "/Home/Boxit-BDOHR/Test/test.txt" "D:\FTP\test\test.txt"

2 1 20110406155516 20110406155516 "/Home/Boxit-BDOHR/Test/test1.xlsx" "D:\FTP\test\test1.xlsx"
Kind regards

Steve

Reply with quote

Advertisement

CountryDave
Guest

Re: Issuing List command to remote directory and output to file

I found a work around to this limitation.

Lets say that you trying to list the files in a directory that end
with .txt.

Your command would need to be modified as such..

Original:
"C:\Program Files\Winscp\winscp.exe" /console /script=D:\FTP\listtest.txt
New:
"C:\Program Files\Winscp\winscp.exe" /console /script=D:\FTP\listtest.txt | find ".txt" > file_list.txt
This new command should pipe the output from the ls through the find command
and only output the results to file_list.txt.

Now if you want just the file names and not the file permissions, date and other
information, you can download gawk from sourceforge
https://gnuwin32.sourceforge.net/packages/gawk.htm

You will need to create txt.awk file. Inside that file put {print $10} and save it.
Then modify your command to
"C:\Program Files\Winscp\winscp.exe" /console /script=D:\FTP\listtest.txt | find ".txt" | "C:\<path to gawk.exe>" -f txt.awk > file_list.txt
That should produce a file called file_list.txt with just the filenames of
files within a directory that meets the *.txt criteria.

I hope this wasnt too confusing.

Reply with quote

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

Re: Issuing List command to remote directory and output to file

"C:\Program Files\Winscp\winscp.exe" /console /script=D:\FTP\listtest.txt | find ".txt" | "C:\<path to gawk.exe>" -f txt.awk > file_list.txt
It cannot work with winscp.exe, you have to use winscp.com

Reply with quote

Tanveer Munavar
Guest

output the directory listing to list file to move the files

Im trying to run the batch file with below script.
winscp.com/script=C:\Users\Tanveer\Documents\PowerShell\connection_test_new.txt > C:\Users\Tanveer\Documents\test\interface_list.lst
calling below connection_test_new.txt script in the batch file.
# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect
open adccopd@54.194.250.198
# list the files
ls /development/cop/data/OUTBOUND/COP_INTERFACES/ADD/ARCHIVE
# Disconnect
close
# Exit WinSCP
exit
unfortunately the output is like below .
batch           abort     
confirm         off       
Searching for host...
Connecting to host...
Authenticating...
Using username "user".
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] user@example
-rw-r--r--   1 adccopd  infagrp         79 Jun 19 12:46:10 2014 ORD094140616130015.csv
-rw-r--r--   1 adccopd  infagrp        158 Jun 19 12:46:09 2014 ORD092140616130015.csv
drwxrwxr--   4 copadm   infagrp       4096 Mar 21 12:50:38 2014 ..
drwxrwxr--   2 copadm   infagrp       4096 Jun 19 12:46:11 2014 .
Session 'adccopd@54.194.250.198' closed.
No session.
Im expecting a result like this.
d----         7/10/2014   2:13 PM            Archive                                                                                 
-a---         6/19/2014  12:46 PM        158 ORD092140616130015.csv                                                                  
-a---         6/19/2014  12:46 PM         79 ORD094140616130015.csv   
Please suggest how this could be accomplished.

Reply with quote

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

Re: output the directory listing to list file to move the files

Tanveer Munavar wrote:

Im expecting a result like this.
d----         7/10/2014   2:13 PM            Archive                                                                                 
-a---         6/19/2014  12:46 PM        158 ORD092140616130015.csv                                                                  
-a---         6/19/2014  12:46 PM         79 ORD094140616130015.csv   
Please suggest how this could be accomplished.
WinSCP has fixed ls format. You cannot change it.
If you want custom format, use WinSCP .NET assembly with its Session.ListDirectory method and format the output as you like.
See https://winscp.net/eng/docs/library_session_listdirectory
Check PowerShell example, if you have no other language preference.

Reply with quote

Advertisement

You can post new topics in this forum