Skip to main content

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.

· 3 min read
View raw
Christophe
Markdown, WSL and Docker lover ~ Insatiable curious.
Cet article existe aussi en français — lire la version française.

This article is over a year old but was reviewed on July 30, 2026 — the content is still accurate.

WinSCP - Synchronize host and remote

⚡
TL;DR

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
exit

This 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​

  1. Save the previous script as, f.i., c:\temp\synchronize.txt
  2. Edit the script and specify:
    1. in case of need, replace ftp by sftp
    2. USERNAME: the FTP username
    3. PASSWORD: the password associated to this account
    4. HOST_OR_IP: the FTP host name or its IP
    5. PORT: the port to use (21 for an FTP connection f.i.)
    6. The local folder where your files are stored (line lcd "C:\Christophe")
    7. The remote folder from where the files should be copied (line cd /Christophe), can be the ftp root or any subfolder
  3. Start a DOS session
  4. Run cd \temp
  5. Run winscp.com from 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).

Was this article helpful?
Did you try the steps in this article?