I recently came across a problem where I needed to schedule the daily FTP upload of a set of files to one of my client’s FTP servers. I was a bit out of my element and found that locating a solution to this task was surprisingly challenging. I thought I would post the steps here so that someone in a similar situation might benefit from the time I spent in trial and error.
1. My first goal was to make sure I could upload via ftp using the command prompt in Windows XP. I created the following script, ftp_script.txt, which I placed in a scripts folder on the C drive:
open www.yourhostname.com
username
password
put c:\test.txt test.txt
quit
Plug in your corresponding hostname, username, password, and file locations. This script will upload the local copy of test.txt to the server. The above script can be passed into your command line ftp client. Open up your command prompt and type:
ftp -s:path_to_script\scriptfile
Which, in my case, was:
ftp -s:c:\scripts\ftp_script.txt
The “-s” allows you to specify a file name in order to pass your username, password, and put commands to the command line ftp client.
2. If you get Step 1 working, the next step is to create a command file to run the ftp script. The command file is just a text file with a .cmd extension that calls up the command line ftp. In my case, I created ftp.cmd with the contents:
ftp -s:c:\scripts\ftp_script.txt
Test your command file by double clicking it to make sure that it executes the FTP successfully.
3. Finally, create a daily task using the Windows Task Scheduler. Go to Start > Control Panel > Scheduled Tasks (in Classic view). Click Add Scheduled Task and when it prompts you for the application, browse to your command file that you created in Step 2. As you finish out the task scheduler, you’ll get to choose how often you want the task to run and at what time.
After you complete these steps, your ftp job should be ready and waiting for its next scheduled execution time. I hope you find this trick as useful as I did!
November 28th, 2011 at 2:15 am
open ftp:username:[email protected]_of_server:21
option batch on
option confirm off
option exclude “*.csv”
option transfer binary
cd /path of FTP server folder/
lcd “path of local folder”
get *.format of the file (for exp: .gz for compressed file,.csv for csv files etc)
exit
November 29th, 2011 at 2:37 pm
[…] here so that someone in a similar situation might benefit from the time I spent in trial and error.http://www.isinc.com/2008/11/19/using-windows-xp-task-scheduler-to-automate-an-ftp-upload/ Share this:TwitterFacebookLike this:LikeBe the first to like this post. Tags automate, courses, […]
June 21st, 2012 at 1:35 pm
THANK YOU VERY MUCH..after trying lots and lots of complicated batch file which never worked on schedule task.Your script saved my life…
August 21st, 2012 at 12:45 pm
Thanks very much for the code. I created the .txt file and ran the ftp command from the command line and it worked perfectly. However, when I created the .cmd file and ran it, a command window opened and started repeating the command from the .cmd file (ftp -s:c:\ftp_script) over and over. I had to ctrl c to get out of it. Any thoughts on what might cause that. I tried it on an XP desktop and Server 2003 with the same result.
Thanks again.
August 21st, 2012 at 1:09 pm
Update:
I changed the contents of the .cmd file to:
http://ftp.exe -s:c:\ftp_script.txt
and it works.
August 21st, 2012 at 2:24 pm
Glad you got it working Mike.
June 8th, 2013 at 2:56 am
thank you zach & nikhil this works very well folr me
June 16th, 2013 at 4:43 pm
Thanks for posting.!this will help me with a task I have been assigned to figure out how to get pump logs from a remote location back to home office. Since it is in a remote location I have only dial up. Is there a way to script making a dial up connection and then the FTP then hang up?
July 1st, 2013 at 9:31 am
I love you man, you are the man!!
July 2nd, 2013 at 7:41 am
Very well explained. It works.
Thank you,