Windows

Batch file to send or receive files into FTP Server

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 :

  1. username : change this line with username login to ftp server
  2. password : FTP passwor
  3. lcd : use this command to change our local working directory where it containing files which will be uploaded to the FTP server.
  4. cd : use this command to change remote FTP directory where we will put the files.
  5. prompt : use this command to disable interactive mode, every prompt will be considered as Yes.
  6. mput : this command will upload all files from local working directory to the remote FTP directory.
  7. 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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s