Automating File Syncing with FTP Server using WinSCP

File Syncing has become one of the necessity now when you switch to different devices. I love Dropbox which does pretty good job in syncing the files across devices. It also uses advanced techniques to sync only the Binary Delta changes which gives good performance considering your bandwidth for large files. Here i am going to share a script which helps to sync a file between local and any ftp server using WinSCP.

WinSCP is a great client for FTP/SFTP Secure File Transfer. There are some hidden gems in WinSCP through which we can automate variety of complex workflows. Click here to download the WinSCP Client Tool. Once Installed it comes with 2 both Graphical and CommandLine application. In this post we are going to look how to sync files using the WinSCP “synchronize” command and thus automating them using a .bat script and Windows Task Scheduler.

Navigate to this Path (based on your installation location) C:\Program Files (x86)\WinSCP\. You can see two application named “WinSCP”.
1.WinSCP.exe : Graphical Interface for File Transfer
2.WinSCP.com : A Commandline Version of File Transfer

 

set winscp=D:\Workspace\Sync\WinSCP\WinSCP.com 

echo option batch continue > script.tmp

echo option confirm off >> script.tmp

echo open myftpProfilefromWinSCP >> script.tmp

echo synchronize local D:\Workspace\Sync\Images /Blog/Images >> script.tmp

echo exit >> script.tmp

%winscp% /script=script.tmp

del script.tmp

Script Explanation :

– In set winscp you need to provide the path of the commandline WinSCP.com. Alternatively you can copy the file and place them in your workspace
– “myftpProfilefromWinSCP” is the profile created in the WinSCP GUI. The script uses this profile information like Server,username and Password to connect to the FTP.
– The synchronize is the important command which does the job of syncing the latest changes either to local or remote based on parameter.

%d bloggers like this: