I frequently download or upload files using FTP. When I release new software I need to upload a new binary file and I frequently backup sections of the site - the forums for example. The backup needs to be run automatically every day so it is convenient to have a batch file that is started at boot-up.
To start, make two new text files in the same directory. Name the first file job.bat and name the second file commands.txt.
Open job.bat in notepad and type the following lines:
ping 1.1.1.1 -n 1 -w 5000 >NUL
ftp -s:command.txt www.mysite.com
Explanation:
The ping command will pause the batch file 5 seconds. Just to ensure a network connection will be in place when the batch file is started at bootup.
The ftp command connects to the site
www.mysite.com and uses the command file command.txt
Open the command.txt file in notepad and type the following lines:
user
pass
cd mydir
ascii
prompt
lcd c:\mydir
mget *
bye Explanation:
user and pass are the username and password to connect through FTP
You can use cd to change directory to the directory where you want to upload or download
You use the lcd command to change the directory on your local PC.
ascii sets the transfer mode to text mode. Use the binary command to set the transfer mode for binary files
prompt sets the interactive mode on or off. I will be getting multiple files and I do not want to be prompted for every file.
mget will get all the files specified. Use get to get one file. Use mput to put multiple files and use put to get one file.
bye will close ftp and will return to the batch file.
To automatically run the batch file at startup you need to put a shortcut to the batch file in your Start | Programs | Startup folder.