Our developer team tell that the application which installed at one of our customer cannot send or receive files into an their FTP server. I try to connect to the FTP server, and all process is running well with no problem so I tell them to send using command line instead. They ask me is possible to make a batch script and put it at task scheduler to automatically send or receive files from/to the FTP server every ten minutes? I think is possible, but I haven’t done this before.
With the information I found here, then I need to create two files to perform each task. The first one was the batch file which will be triggered by Task Scheduler to run every 10 Minutes. Lets name the first file : ftp_upload.bat . This files contains the following code :
@echo off ftp -s:ftpuploadcommand.txt ftp.server.address
The first line : @echo off is used so every line command doesn’t displayed on the screen, then the second line is used to attached ftpuploadcommand.txt file which containing all FTP command that will be used for upload process and also define ftp server name or IP address.
The second file as I mentioned above : ftpuploadcommand.txt which containing the following ftp commands :
username password lcd "path-to-local-working-directory" cd "path-to-remote-directory" prompt mput *.* bye
The above command should be clear but let me explain each line :
- username : change this line with username login to ftp server
- password : FTP passwor
- lcd : use this command to change our local working directory where it containing files which will be uploaded to the FTP server.
- cd : use this command to change remote FTP directory where we will put the files.
- prompt : use this command to disable interactive mode, every prompt will be considered as Yes.
- mput : this command will upload all files from local working directory to the remote FTP directory.
- bye : use this command to close the FTP connection
That’s it, batch file to upload files to FTP server is ready. The next step we have to do is create a Task Scheduler to automatically run ftp_upload.bat script every 10 minutes. For how to create a task scheduler, you can found in another article here. Thank you