FTP download

February 1, 2012 at 12:00:15
Specs: Windows 7
I am looking to create a batch file that will login to the FTP server via the ip address and download the newest file to a network drive.

The FTP site names the daily file with the name (i.e 20120131.ABC.zip). The first set of numbers is the date and this part changes each day for the previous days date.

So basically i need to log in get the newest file by date and download it to my z:\acb directory

See More: FTP download

Report •

February 2, 2012 at 20:23:49
This isn't tested but it should be close to what you need. You need to replace yourusername, yourpassword, and yourhost.com with your own credentials and your ftp server address. Also, this won't work on the first of the month because 1-1=0, but that could be fixed.

@echo off

REM breaking up date to construct remote file name
set year=%date:~10,4%
set month=%date:~4,2%
set monthday=%date:~7,2%
set /a yesterday=%monthday% - 1

REM creating ftp commands list
echo USER yourusername > ftpcommands.txt
echo yourpassword >> ftpcommands.txt
echo binary >> ftpcommands.txt
echo prompt n >> ftpcommands.txt
echo mget %year%%month%%yesterday%.ABC.zip >> ftpcommands.txt

REM changing directory
cd acb

REM executing ftp operation
ftp -v -s:ftpcommands.txt ftp.yourhost.com


Report •

February 3, 2012 at 08:16:54
set /a yesterday=%monthday% - 1
Today is the first day of the month. Now what?

How To Ask Questions The Smart Way

Report •

February 3, 2012 at 10:02:23
Hi Razor2.3,

That's why I said:

"Also, this won't work on the first of the month because 1-1=0, but that could be fixed."

I just need to add something like:

if %yesterday% equ 0 set /a lastmonth=%month% - 1
if %lastmonth% equ 0 set lastmonth=12
if %lastmonth% equ 12 set yesterday=31
if %lastmonth% equ 11 set yesterday=30
if %lastmonth% equ 10 set yesterday=31
if %lastmonth% equ 09 set yesterday=30
if %lastmonth% equ 08 set yesterday=31
if %lastmonth% equ 07 set yesterday=31
if %lastmonth% equ 06 set yesterday=30
if %lastmonth% equ 05 set yesterday=31
if %lastmonth% equ 04 set yesterday=30
if %lastmonth% equ 03 set yesterday=31
if %lastmonth% equ 02 set yesterday=28
if %lastmonth% equ 02 if %year% equ 2012 if %year% equ 2016 if %year% equ 2020 if %year% equ 2024 if %year% equ 2028 set yesterday=29
if %lastmonth% equ 01 set yesterday=31

Report •
Related Solutions

Ask Question