IT Support Diary Everyday IT support issues and solutions

Batch file using WGET to download from FTP

02.10.2010 · Posted in Tools

One batch file that will allow you to download certain dated files while excluding some folders using WGET.

I need to download files from an FTP site:

and these are the conditions:

1) Download all files except the ones with extentions .R, .A, .C, .E, .P, .A

2) Download only files starting with 0066, 7019, 0124, 2039, 5002, 5003, 0064, 5244, and 0660

3) Exclude folders archive and batch

4) Download only yesterday files – the files on the FTP have MMDD at the end.

This is the batch file:

FOR /f “tokens=1-3 delims=/ ” %%a in (‘DATE/T’) do set date=%%b%%a
FOR /f “tokens=1-3 delims=/ ” %%a in (‘DATE/T’) do set day=%%a
FOR /f “tokens=1-3 delims=/ ” %%a in (‘DATE/T’) do set month=%%b

REM ———————————————————
REM Test by setting the next two variable to a day and month
REM SET day=01
REM SET month=04
REM ———————————————————

SET /a iDay=%day:~0,1%
SET /a iMonth=%month:~0,1%

ECHO iDay IS: %iDay%
ECHO iMonth IS: %iMonth%

if %iDay%==0 (SET /a iDay=%day:~1,2%) else (SET /a iDay=%day%)
if %iMonth%==0 (SET /a iMonth=%month:~1,2%) else (SET /a iMonth=%month%)

ECHO iDay1 IS: %iDay%
ECHO iMonth1 IS: %iMonth%

REM —————————————————–
REM If first day of month then rollback to previous month
REM —————————————————–

if %iDay% EQU 1 GOTO :CheckMonth
if %iDay% NEQ 1 GOTO :DecrementDay

if %iMonth% NEQ 1 GOTO :DecrementMonth
if %iMonth% EQU 1 SET /a iMonth=12
GOTO :LastDayOfMonth

SET /a iMonth=%iMonth%-1


REM ——————————————————-
REM Now figure out the correct day  number for the new month
REM ——————————————————-
if %iMonth% EQU 1 SET /a iDay=31
if %iMonth% EQU 2 SET /a iDay=28
if %iMonth% EQU 3 SET /a iDay=31
if %iMonth% EQU 4 SET /a iDay=30
if %iMonth% EQU 5 SET /a iDay=31
if %iMonth% EQU 6 SET /a iDay=30
if %iMonth% EQU 7 SET /a iDay=31
if %iMonth% EQU 8 SET /a iDay=31
if %iMonth% EQU 9 SET /a iDay=30
if %iMonth% EQU 10 SET /a iDay=31
if %iMonth% EQU 11 SET /a iDay=30
if %iMonth% EQU 12 SET /a iDay=31
GOTO :ScriptEnd

SET /a iDay=%iDay%-1


if %iDay% LSS 10 (SET day=0%iDay%) else (SET day=%iDay%)
if %iMonth% LSS 10 (SET month=0%iMonth%) else (SET month=%iMonth%)

MOVE D:\Test\logs\ftpsync.log D:\Test\logs\%month%%day%_ftpsync.log

wget –passive-ftp -R “A”,”C”,”E”,”P” -A “0066*%month%%day%*”,




-X “archive”,”batch” -m -nH -P d:\Test\ -a D:\Test\logs\ftpsync.log

Leave a Reply