How To download file with latest date only at remote folder

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kentck86
Posts: 2
Joined: 11 Dec 2015 10:41

How To download file with latest date only at remote folder

#1 Post by kentck86 » 11 Dec 2015 10:46

Hi Guys,

I am having the following code which search for specific filename in remote folder to download to local folder. How can i edit this to be searching for latest date file in remote folder to be downloaded.Thank you

@Echo Off
Set _FTPServerName=60.250.148.123
Set _UserName=ABC
Set _Password=1234
Set _LocalFolder=C:\Users\User\Desktop\Test
Set _RemoteFolder=/Download/NMC/
Set _Filename=alarm_20151211.rar
Set _ScriptFile=ftp1
:: Create script
>"%_ScriptFile%" Echo open %_FTPServerName%
>>"%_ScriptFile%" Echo %_UserName%
>>"%_ScriptFile%" Echo %_Password%
>>"%_ScriptFile%" Echo lcd %_LocalFolder%
>>"%_ScriptFile%" Echo cd %_RemoteFolder%
>>"%_ScriptFile%" Echo binary
>>"%_ScriptFile%" Echo get %_Filename%
::>>"%_ScriptFile%" Echo quit
:: Run script
ftp -s:"%_ScriptFile%"
Del "%_ScriptFile%"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How To download file with latest date only at remote folder

#2 Post by foxidrive » 12 Dec 2015 04:14

If the filenames contain the date then they can be made to sort by date.

Using the FTP log file is the only other way, and the actual log file of the FTP listing will show us if that can be done.

Here's some info: http://stackoverflow.com/questions/1155 ... and-window

kentck86
Posts: 2
Joined: 11 Dec 2015 10:41

Re: How To download file with latest date only at remote folder

#3 Post by kentck86 » 14 Dec 2015 09:17

foxidrive wrote:If the filenames contain the date then they can be made to sort by date.

Using the FTP log file is the only other way, and the actual log file of the FTP listing will show us if that can be done.

Here's some info: http://stackoverflow.com/questions/1155 ... and-window


Hi,

I dont get it. could you list the procedure here please.

thank you

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: How To download file with latest date only at remote folder

#4 Post by foxidrive » 14 Dec 2015 09:36

kentck86 wrote:I dont get it. could you list the procedure here please.


This provides a listing of a folder. We need to see the same thing from the folder on your FTP server, showing the files.

Code: Select all

@echo off
set "site=ftp.microsoft.com"
(
echo.open %site%
echo.user anonymous password
echo.dir
)| ftp -n >log.txt

Post Reply