Date de publication : Dec 16, 2008 9:9:39 AM
(via http://www.christianschenk.org/blog/automate-ftp-sessions-windows/)
open example.com
username
password
cd another-directory
mput C:\files\file*.txt
bye
It will open a connection to the given host using the supplied username and password. Then it will change the working directory on the server to another-directory and finally upload some files. Adapt everything to your needs; if you’d like to use more FTP commands, this is a good starting point.
Next we’ll create a batch script that calls the ftp command using the text file that we’ve just created. Save the following into a batch file (upload.bat):
@echo off
@set logfile=upload.log
@ftp -i -v -s:"upload.ftp" > %logfile%
@del %logfile%
It creates a log file (upload.log) and deletes it after the ftp command is finished - if you’d like to keep the log file remove the last line from the script.
Now you have a batch file that you can click on and the files will be uploaded to the FTP server. Although this was pretty easy to setup is has a great impact: You don’t have to do this manually any more.
While the script that you’ve just created is fully functional you may want to run it automatically every now and then. To do this, you’ll have to:
make sure that the script uses absolute path names
add a task to the at scheduler
First put the batch script and the text file into a directory of your choice. Add the path to this directory in front of log file’s name in line two of the batch script and to the text file containing the FTP commands in line three.
At last you can add a recurring task with at like so:
at 22:30 /every:M,T,W,Th,F,S,Su C:\Scripts\upload.bat
In this case the script that I put under C:\Scripts will run every day at 22:30, i.e. 10:30 pm.