|
Answer» Hi All,
I need help with comparing the filenames in a DIR and get the latest ONE over FTP. The directory on the FTP server has N number of files, all suffixed with MODIFIED date. For e.g : Test_20131125.txt Test_20131124.txt Test_20131123.txt.
The filenames will always begin with Test_ but the date portion will vary. Now I have to get the latest one among these which would be Test_20131125.txt in the example. I want to use a batch file to do so but not sure how to go about it.
Thanks, KhushbooThe steps you need are:
log in to the FTP server do a DIR quit
The DIR has to be CAPTURED to a text file and you will need to filter and parse the text file to extract the latest file, using SORT to give you a sorted list, where you extract the first filename.
Then you log in again download the file quit
FTP is a pita.
To get a script you will need to provide an actual log from the FTP server using DIR so that the method to parse the list can be developed, as FTP servers do not all return the directory listing in the same format. Thank you very much. I am able to list the files on the server to a local text file using the following commands: open ftpserver username password cd testdir prompt ls * ftplist.txt disconnect bye
The filesnames get listed in the ftplist.txt on the local server and its contents now look like : Test_20131122_0307.xls Test_20131125_0306.xls
I have to get the filename based on the date i.e Test_ will remain the same and I should sort based on the datepart of the filename. How do I do that? This depends on the prefix in the files remaining constant:
Code: [Select]@echo off for /f "delims=" %%a in (' sort ^< "ftplist.txt" ') do set "filename=%%a" echo "%filename%" pause
|