Monday, August 22, 2011

WinSCP synchronize scripting example

depending on how automated you need this script to be (I need very much to do it daily on it's own) so in my case I created this file example.txt:

option batch abort
option confirm off
open ftp://username:password@ftphost
synchronize local c:\local\path /path/on/server
 Now this is the first part for local, so downloading everything new on the server to the local directory, next we have to put either in same file between the synchronize command and exit or I tried in new file example2.txt:
option batch abort
option confirm off
open ftp://username2:password2@ftphost2
synchronize remote c:\local\path /path/on/server2
Note: If you need it to be SFTP instead of ftp:/ simply take that part out to look like this: open username2:password2@ftphost2
Getting the same thing to a secondary server with different username and pass of course,  this means we are replicating not only locally but also on a second server (for maximum redundant and backup if you have an important application like I do).

And for automation purpose I have a script called ftp.bat with following:
"progs\WinSCP.exe" /script=c:\path\to\example.txt /log=c:\path\to\logs\sftplog.txt
"progs\WinSCP.exe" /script=c:\path\to\example2.txt /log=c:\path\to\logs\sftplog.txt

Finally it's pretty easy to create a scheduled task (instructions will be coming soon if there's demand for this, leave a comment below) simply to point to ftp.bat and start it daily when you wish to do it!

Leave any feedback please


Anonymous said...

This was most helpful. Thank you!

Anonymous said...

Thanks a Million. Very Helpful.

Diego said...

THANK YOU! This worked great.

Anonymous said...

Still relevant - thanks.