WinSCP - Synchronize host and remote
Use a script with WinSCP to easily synchronize files between your local host and a remote FTP/SFTP server. Learn the commands for local, remote, or bi-directional synchronization.
This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.
This article is part of the WinSCP & remote file transfer series:
- KeePass - Overriding the URL field
- WinSCP - Retrieve a stored password
- Fatal error was starting Putty after having saved settings
- WinSCP - Synchronize host and remote
- FTP - Remove files and folders at light speed
- WinSCP - Visual Basic for Application use
- WinSCP - Download files with specific extension recursively
- Search your FTP server at lightning speed

This article shares a WinSCP script that synchronizes a local folder with a remote FTP/SFTP server (or vice versa) via the synchronize command, run with winscp.com /script=.... It explains the local/remote/both direction options, useful for automated backups like syncing a folder to a Synology NAS.
By the use of a script, it's possible to ask WinSCP to synchronize your host and remote machine i.e. if a file is newer on the host, copy it to your remote server and the opposite.
If a file has been added to your host, copy it to your remote server and vice versa.
I'm using such script for making a full backup of some of my folders to my Synology. I've also used it for years to deploy this very blog, before switching to GitHub Actions.
Two more WinSCP scripts on this blog: downloading files with a specific extension recursively and opening a WinSCP session straight from KeePass.
The script
open ftp://USERNAME:PASSWORD@HOST_OR_IP:PORT/
option transfer ascii
lcd "C:\Christophe"cd /Christophe
synchronize remote -preservetime -transfer=automatic -filemask="|.git/"
close
exitThis is an FTP script that connects to a remote server, changes to specific directories on both the local machine and remote server, then synchronizes files between them while excluding the .git folder. Finally, it closes the connection and exits.
How to use
- Save the previous script as, f.i.,
c:\temp\synchronize.txt - Edit the script and specify:
- in case of need, replace
ftpbysftp USERNAME: the FTP usernamePASSWORD: the password associated to this accountHOST_OR_IP: the FTP host name or its IPPORT: the port to use (21 for an FTP connection f.i.)- The local folder where your files are stored (line
lcd "C:\Christophe") - The remote folder from where the files should be copied (line
cd /Christophe), can be the ftp root or any subfolder
- in case of need, replace
- Start a DOS session
- Run
cd \temp - Run
winscp.comfrom there: type"c:\program files (x86)\WinSCP\WinSCP.com" /script="c:\temp\synchronize.txt"
If everything is correctly set up, WinSCP will start a session terminal and will start the synchronization.
More info
More info about the Synchronize verb of WinSCP: https://winscp.net/eng/docs/scriptcommand_synchronize.
- If files/folders are already there, don't do anything.
- If there are new files/folders, copy them.
- If files/folders are no more on the local drive, remove them from the remote server.
So local is the master.
Local / Remote / Both
See the line synchronize remote.
Choose remote, local or both:
- When the first parameter is
local, changes from remote directories are applied to local directories. - When the first parameter is
remote, changes from the local directories are applied to the remote directories. - When the first parameter is
both, both local and remote directories can be modified (source).
This article is part of the WinSCP & remote file transfer series:
- KeePass - Overriding the URL field
- WinSCP - Retrieve a stored password
- Fatal error was starting Putty after having saved settings
- WinSCP - Synchronize host and remote
- FTP - Remove files and folders at light speed
- WinSCP - Visual Basic for Application use
- WinSCP - Download files with specific extension recursively
- Search your FTP server at lightning speed


