Two way synchronization in WinSCP

2

1

I am in an SSH session with a remote machine using WinSCP. I would like WinSCP to track a file on my local machine, call it test.cpp. That is, whenever this file is updated on my local machine, the change should automatically be made on the remote.

At the same time, I would like WinSCP to track a file on the remote, call it out.txt, so that changes to this file on the remote are reflected on my own machine.

How can I achieve both of these simultaneously? I want the first file to be tracked in one direction, and the other to be tracked in the other direction, but neither file should be tracked in both directions.

user308485

Posted 2018-06-04T13:27:00.353

Reputation: 123

WinSCP is the wrong tool for this job. If you are using UNIX/Linux and don't need literal immediate sync (e.g. syncing on a schedule is OK) look into rsync. – LawrenceC – 2018-06-04T13:54:54.223

Actually I am looking for immediate synchronization. Also, my local machine is Windows (the remote is Ubuntu). – user308485 – 2018-06-04T13:56:32.107

There's rsync for Windows (many UNIX/Linux utilities have Windows versions) - easy to find with search. If you want immediate synchronization without repeated polling then you probably need a specialized tool (can't think of one designed just for this use), or setup a Samba server on the Ubuntu side and use Windows to access the Samba share. – LawrenceC – 2018-06-04T13:58:34.433

Answers

0

Just create a batch file that runs in a loop, running put -neweronly for test.cpp and get -neweronly for out:

@echo off
:loop
winscp.com /ini=nul /command ^
    "open sftp://username:password@example.com/ -hostkey=""ssh-rsa 2048 ...""" ^
    "put -neweronly C:\local\path\test.cpp /remote/path/*" ^
    "get -neweronly /remote/path/out C:\local\path\*" ^
    "exit"
timeout /t 30
goto loop

(WinSCP GUI can generate a batch file template for you)


If you want to keep the connection open (not to reconnect for each iteration), you better use WinSCP .NET assembly from a PowerShell script.

See Keep local directory up to date (download changed files from remote SFTP/FTP server) for an example.

Martin Prikryl

Posted 2018-06-04T13:27:00.353

Reputation: 13 764