Reputation: 13
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 there are 3 files on the FTP server : 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,
Upvotes: 0
Views: 151
Reputation: 7095
Here is how I would do it:
Something like this:
MD %temp%\ftpdown
ftp -s:myftp.txt
for /f %%a in ('%temp%\ftpdown dir /b /od') set latest=%%a
copy /Y %latest% wherever
rd /q /s %temp%\ftpdown
This is fine if there are only a few smallish files because you're downloading them all locally to do the compare. If it's a large directory or the files are big, it's better to download a dir/ls listing from the server and extract the filename from it then write an ftp script file to get than file. It all depends.
Upvotes: 1