Topic "Issuing List command to remote directory and output to file"

Author Message
me119394
[View user's profile]

Joined: 2010-01-12
Posts: 5
Location: London
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.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
You cannot redirect output of WinSCP scripts. You can use XML logging instead.
http://winscp.net/eng/docs/logging_xml
Guest




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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
For examples, follow the links at the end of the article.
_________________
Martin Prikryl
me119394
[View user's profile]

Joined: 2010-01-12
Posts: 5
Location: London
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"[/b]


Kind regards

Steve
CountryDave

Guest


me119394 wrote:
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.



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
http://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 10.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.
CountryDave

Guest


CountryDave wrote:
me119394 wrote:
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.



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
http://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 10.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.



Sorry the final command would be

"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
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Quote:
"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
_________________
Martin Prikryl
Tanveer Munavar

Guest


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.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
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 http://winscp.net/eng/docs/library_session_listdirectory
Check PowerShell example, if you have no other language preference.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License