Automatic FTP upload with Windows
21 maggio 2008, 0:38 Tips & tricks , Windows May 21, 2008, 12:38
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:
| ||||||||||||
| 3. |
Type a name for the operation and select from the following options:
| ||||||||||||
| 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`.















November 27th, 2008 at 13:11
Hello! How can I upload to my server automatically an entire folder (with all its contents, I do not know a priori) periodically automatically?
Hello and Thanks!
November 27th, 2008 at 15:19
Hello kumo,
I think that in my instructions there is virtually everything you need. What is the point that you do not understand? Let me know: I give a willing hand.
Hello
Ivan
November 27th, 2008 at 18:03
Hello! I can not upload the folder! With none of these attempts:
C: \ Documents and Settings \ FedeCri \ Desktop> uploadme C: \ Avatar
C: \ Documents and Settings \ FedeCri \ Desktop> uploadme C: \ Avatar \
C: \ Documents and Settings \ FedeCri \ Desktop> uploadme C: \ Avatar \ *.
He returns "error opening file AVATAR" ... it is as if wildcards do not work ...
December 2nd, 2008 at 10:58
Ivan?? Would you help me x fav?
December 2nd, 2008 at 12:00
Kumo Hello! And yet I forgot about you, as I did not know
I think the solution to your problem is simple: Replace the education which is put at 6 to line of the batch that I published in my post with the statement mput. Here's the final script:
@echo offecho user UTENTE> ftpcomm.dat
echo QWERTY>> ftpcomm.dat
echo bin>> ftpcomm.dat
echo cd /MIA/CARTELLA/>>ftpcmd.dat
echo mput %1>> ftpcomm.dat
echo quit>> ftpcomm.dat
ftp -n -s:ftpcomm.dat http://FTP.ESEMPIO.NET
del ftpcomm.dat
Okkio, I have not tried because I have no time right now, but it should work ... Let me know how it went anyway, OK?
Ivan Agliardi
December 2nd, 2008 at 16:49
Thank resp, Ivan, but the situation has worsened over ... not to upload an entire folder, now I do not charge even a single file ... I get stuck at this point:
ftp> bin200 TYPE is now 8-bit binary
ftp> mput stewie.jpg
mput stewie.jpg? quit
ftp>
December 2nd, 2008 at 17:00
Interesting ... could it be that ftp prompt mode from the command line of Windows is on by default with mput.
I still do not have access to a Windows machine to do this test, then I give you straight, you try, and if I confirm it works ... ok? If we look just does not work ... So I have two minutes, try this:
@echo offecho user UTENTE> ftpcomm.dat
echo QWERTY>> ftpcomm.dat
echo bin>> ftpcomm.dat
echo cd /MIA/CARTELLA/>>ftpcmd.dat
echo prompt>> ftpcomm.dat
echo mput %1>> ftpcomm.dat
echo quit>> ftpcomm.dat
ftp -n -s:ftpcomm.dat http://FTP.ESEMPIO.NET
del ftpcomm.dat
Explanation: I added the statement prompt, which offers off interactive prompting (line 6). Try and let me know.
I wait expectantly
Ivan Agliardi
December 2nd, 2008 at 19:30
Thank you! It works!
One last question though '
How do I put code in the folder you want to load WITHOUT having to switch from DOS as a parameter??
Basically I want the little program parts simply clicking 2 times 
December 3rd, 2008 at 8:27
If I understand it you want this simple script includes direct path of the directory to be moved via FTP and does not require it as an argument. Well, one thing is quite simple:
@echo offecho user UTENTE> ftpcomm.dat
echo QWERTY>> ftpcomm.dat
echo bin>> ftpcomm.dat
echo cd /MIA/CARTELLA/>>ftpcmd.dat
echo prompt>> ftpcomm.dat
echo mput C:\avatar >> ftpcomm.dat
echo quit>> ftpcomm.dat
ftp -n -s:ftpcomm.dat http://FTP.ESEMPIO.NET
del ftpcomm.dat
If it does not work (I remember that I always use only Linux and also on the laptop from which I write) will try to replace
echo mput C:\avatar >> ftpcomm.datwith
echo mput C:\avatar\* >> ftpcomm.datLet me know
Ivan Agliardi
December 11, 2008 at 12:11
Perfect Thank you! But because I do not see the wildcards?? For example:
echo mput "C :/ avat * / new / *. gif" >> ftpcomm.dat returns error because I can not find the folder avatar!
December 11, 2008 at 1:20
Kumo Hello, please help ftp under DOS
Ivan
December 11, 2008 at 14:39
Should I transfer must switch from binary to ascii transfers?? yet the end "*. gif" no problems! Why I have problems only with the abbreviation of the folder??
December 12, 2008 at 20:14
Hello Kumo
I too have the same problem ... you have solved?
With 1000
Greetings
July 7, 2009 at 11:53
everything is beautiful, only that there is a small problem but not least, if you use this script and you have some problem connecting the data on the ftp site may get incorrect because there is no data appears between local and remote and here is a little point of no reliable FTP, you got any solution?
July 7, 2009 at 12:57
Hello Daniel,
the post to which you refer is the only public response to a request that I had received, which provided expressly request the use of the FTP protocol only. As you indicate in the limits of which are those proper to speak of the FTP protocol, which does no appear in the source file and destination, although in most scenarios the possible connection problem is detected and the transfer fails, it all depends on the operating system and / or the software that manages the operation. An alternative solution is undoubtedly to use software like rsync under windows. Find a tutorial to make a simple solution using rsync to this address: http://www.fabriziosinopoli.it/2008/02/18/backup-con-rsync-in-windows/
Have fun!