Today I've had to program the automatic upload of a file in Windows XP Professional. It was as always a very instructive: after all, taking the most various tricks, you can also get from Windows is something vaguely similar to the behavior of `cron` on Linux servers. Only vaguely, I will not deceive anyone. But you can do. Here's how.

Suppose you have to move every hour a copy of the file test.txt the following FTP servers:

Host: FTP.ESEMPIO.NET
user: USER
pass: QWERTY
Destination: / MIA / FOLDER /

First we create a batch script that can open an FTP connection, move the file and then close the connection itself.

Here is the script that I created and saved in the file UPLOADME.BAT:

@echo off
echo user UTENTE> ftpcomm.dat
echo QWERTY>> ftpcomm.dat
echo bin>> ftpcomm.dat
echo cd /MIA/CARTELLA/>>ftpcmd.dat
echo put %1>> ftpcomm.dat
echo quit>> ftpcomm.dat
ftp -n -s:ftpcomm.dat FTP.ESEMPIO.NET
del ftpcomm.dat

Simple and straightforward. From the command line publication of the file test.txt is obtained simply by typing:

uploadme "C:\Documents and Settings\Ivan Agliardi\Documenti\PROVA.TXT"

Now is - absurdly - the tricky part. Windows does not have a true system cron, so we have to resort to the infamous Scheduled Tasks (alias task Scheduler).

I quote from http://support.microsoft.com/kb/308569/it :

To open Scheduled Tasks, click the Start button, point to All Programs, Accessories, System Tools, then click Scheduled Tasks.

To schedule a new task:

1. Double-click Add Scheduled Task to start the Scheduled Task Wizard, click Next on the first dialog box.
2. In the next dialog box displays a list of programs installed on your computer as part of the Windows XP operating system or as a result of software installation.

Use one of the following methods:

If the program you want is listed, select it, then click Next.
If you want to run a program, a script or a document that is not listed, click Browse, select the folder and the files you want, then click Open.
3. Type a name for the operation and select from the following options:

Everyday
Every week
Every month
Once
When the computer starts (before a user logs on)
User access (only after the current user's login)
4. Click Next, specify the time information and the day to run the operation, then click Next.

Information regarding the date and time of execution of the operation depend on the selection made in the previous dialog of the wizard. For example, if you select the Weekly option, you must indicate the day of the week, time, and whether the operation should be performed every week, every two weeks, every three weeks and so on.

5. Type the user name and password associated with the operation. Make sure you select a user has sufficient permissions to run the program. By default, the wizard selects the name of the current user that is logged.
6. Click Next, then click Finish after verifying your selections.

End of quote ... Now, the problem a bit 'more serious is that the interface of the Task Scheduler does not offer great choice regarding the timing: if I want to run the script every hour I first create a scheduled task with one of timings available and then modify it by going to its Advanced options.

What there is to execute an advanced event every 7 minutes - for example - instead of once a day, it is unclear to me. I am not clear, however, that the advanced options allow me to set the auto-repeat operation every n minutes, obtaining in fact an early form of `cron`.

Share this content:
  • del.icio.us
  • Google Bookmarks
  • Digg
  • Facebook
  • Technorati
  • MySpace
  • Twitter