Pages

Wednesday, January 21, 2009

Using Windows XP Task Scheduler to Automate an FTP Upload

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!

(from: http://www.isinc.com/2008/11/19/using-windows-xp-task-scheduler-to-automate-an-ftp-upload/)

No comments:

Stats