This batch script will compare your local and remote directories, and download what you do not have locally. This can be perfect for someone that has a seedbox and wants to automate their downloads to their local computer.

Please remember that this script only compares file names and it does not know if the file has had any updates.

You are going to need to add the following script to your batch file:

script.bat

@ECHO off
TITLE Automatic FTP Downloads
CLS
REM ----------------------------CUSTOM CONFIGURATIONS---------------------------------------
 
REM This is your local directory that you use to store your files (Example: C:\Users\johndoe\Documents)
SET LOCALFILEDIR=LOCAL DIRECTORY HERE
 
REM Your FTP credentials
SET FTPUSERNAME=USERNAME
SET FTPPASSWORD=PASSWORD
SET FTPHOST=FTP.HOSTNAME.COM
 
REM Your FTP directory that you would like to download from (Example: www/downloads)
SET FTPDIR=FTP DIRECTORY HERE

REM ------------------------------------------------------------------------------------------
 
 
REM Checking Local Directory
ECHO Checking Local Directory
DIR /b %LOCALFILEDIR%>local.txt
 
REM Sets current directory
CD /d %~dp0

REM Creating FTP script to check remote directory
ECHO Creating FTP Script to check remote directory
ECHO %FTPUSERNAME%>ls_ftp.txt
ECHO %FTPPASSWORD%>>ls_ftp.txt
ECHO ascii>>ls_ftp.txt
ECHO cd %FTPDIR%>>ls_ftp.txt
ECHO ls * remote.txt>>ls_ftp.txt
ECHO bye>>ls_ftp.txt

REM This will create the remote.txt file that has a list of files that are on the server
FTP -s:ls_ftp.txt %FTPHOST% > nul
 
REM ------------------------------------------------------------------------------------------
FOR /f %%i IN ("local.txt") DO SET size=%%~zi
IF %size% gtr 0 (
 
REM Comparing both directories
FINDSTR /V /I /G:local.txt remote.txt > diff.txt
 
REM Creating FTP script
ECHO Creating FTP Script to download remote files
ECHO %FTPUSERNAME%>ftpscript.txt
ECHO %FTPPASSWORD%>>ftpscript.txt
ECHO BINARY>>ftpscript.txt
ECHO cd %FTPDIR%>>ftpscript.txt
FOR /F "tokens=*" %%G IN (diff.txt) DO @ECHO get %%G>>ftpscript.txt
ECHO bye>>ftpscript.txt
GOTO:NOTEMPTY
 
) else (
 
REM Creating FTP script
ECHO Creating FTP Script to download remote files
ECHO %FTPUSERNAME%>ftpscript.txt
ECHO %FTPPASSWORD%>>ftpscript.txt
ECHO BINARY>>ftpscript.txt
ECHO cd %FTPDIR%>>ftpscript.txt
FOR /F "tokens=*" %%G IN (remote.txt) DO @ECHO get %%G>>ftpscript.txt
ECHO bye>>ftpscript.txt
GOTO:Empty
)
REM ------------------------------------------------------------------------------------------
 
:Empty
REM Run script to download the new files
ECHO Running FTP Script
FTP -s:ftpscript.txt %FTPHOST% > nul
 
FOR /F "tokens=*" %%G IN (remote.txt) DO MOVE %%G %LOCALFILEDIR%
GOTO :DEL
 
:NOTEMPTY
REM Run script to download the new files
ECHO Running FTP Script
FTP -s:ftpscript.txt %FTPHOST% > nul
 
FOR /F "tokens=*" %%G IN (diff.txt) DO MOVE %%G %LOCALFILEDIR% 
GOTO :DEL
 
REM ------------------------------------------------------------------------------------------
 
:DEL
DEL /Q local.txt ftpscript.txt diff.txt remote.txt ls_ftp.txt
GOTO :Done
 
:Done
ECHO Done.
pause
[/sourcecode]

If you would like to automate launching this script, you can run the following command to run this script daily at 12:01AM.

SCHTASKS /Create /ST 00:01 /TN "Daily FTP Check" /TR script.batch /SC DAILY