1.

Solve : FTP: using ls to write a directory listing locally?

Answer»

NOT SURE if I'm in the correct forum.. but here goes....

I am connecting to a SECURE FTP site daily to SEND a file to a Vendor.

Here is my script:
open ip.address.of.vendor
usernamepassword
cd uploads
put D:\folder\myfolder\*.csv
quit

this works perfect!!! what I am trying to do is add the LS command to write a remote directory listing locally. This is the only way I can think of to actually check to see if my file was successfully transmitted.

I just want to add an ls command after my put command and PULL a directory listing back to my local machine.. can anyone help with the syntax???

Dunno if this helps

I think you use dir in the local DOS ftp PROGRAM to cause an ls on the remote Unix machine to be written locally.

On this page
http://rotterdam.ics.uci.edu/info/DosFtp.htm

it says

Quote
Using FTP in MS-DOS:

[...]

To list the contents of the current remote directory, type "dir"

ftp> dir
200 PORT command successful.
150 Opening ASCII mode data connection for /bin/ls.
total 240
-rw-r--r-- 1 ea 2607 Apr 23 15:35 FileA.gif
-rw-r--r-- 1 ea 2774 Apr 23 15:37 FileB.htm
-rw-r--r-- 1 ea 11549 Mar 17 20:04 FileC.gif
-rw-r--r-- 1 ea 5707 Apr 23 15:34 FileD.html
-rw-r--r-- 1 ea 416 Mar 17 19:11 index.html
-rw-r--r-- 1 ea 55651 Sep 1 23:54 FileE.jpg
-rw-r--r-- 1 ea 4483 Apr 23 15:37 FileF.ico
226 Transfer complete.
625 bytes received in 0.22 seconds (2.84 Kbytes/sec)

I don't know of a way to do what you want in one step. I think you have to do it in 2 steps. For example, if your current batch is called UPLOADFILES.BAT and your FTP command file is called UPLOADFILES.FTP, you can make a new command file named LISTFILES.FTP like this:

UPLOADFILES.BAT
Code: [Select]ftp -s:uploadfiles.ftp
ftp -v -s:listfiles.ftp >filelist.txt
LISTFILES.FTP
Code: [Select]open ip.address.of.vendor
username
password
cd uploads
ls
quit
Then you can parse your FILELIST.TXT
Thanks GuruGary. That is what I was looking for! I get back a directory listing from the remote end written to a .txt file - I don't get a date/time stamp on the file, but the filename contains the current date, so that should be good enough.

Thank you for your help!If you want the timestamps, try replacing the "ls" command in the LISTFILES.FTP with "dir".


Discussion

No Comment Found