FTP from a BAT File
Let’s say you have some files you need to upload or download somewhere at night using FTP. This can be the case with a server, or if you have some backup files, or even website files that you may want to handle this way. One way to automate it is with a BAT file, and then set it on a scheduled task in windows. So let’s look at writing a BAT file that would automate the upload, or download of files using FTP.
The way I usually do this is with two scripts. One being the actual BAT file that runs the command, and the second being the FTP script that contains all the FTP commands we need. We’ll start by looking at the BAT file as it is very simple, basically it looks like this.
ftp -v -i -s:ftpscript.txt
Basically this is just an FTP command with a few parameters that then runs the FPT script. It is the FTP script in this case that I will spend more time looking at. So let’s look at the ftpscript.txt file, which should look something like the following.
!:— FTP commands below here —
The first part of the script is pretty basic, using the open command it connects to your FTP server, then gives your server your username and password to login. After that it runs the actual commands, first using lcd to change directory location on your computer to the directory of the files you want FTP’d. In this case it is the C:\downloads\test folder. Then it does a cd command to change to the directory on the FTP server that you want the files sent to. In this example it is the \public_html\test folder on your FTP server we are putting the files. The script then changes the type to binary, and using mput *.* it uploads all the files in the test directory to your FTP server. Then the script disconnects from the FTP server and is done.
The above example shows how to upload files from a local computer to a remote FTP server, but what if you wanted to download the files from an FTP server to your computer. That is actually quite easy, in the like where it says mput “*.*” simply change mput to mget, so the line reads mget “*.*”, it’s that simple.
So if you are looking for a quick easy way to FTP files back and forth with your computer, or even automate it with a scheduled task, try this little FTP BAT file trick. It might just be what you’re looking for.