Synchronize Files in Realtime from a Windows PC to a Linux Box

You may also like...

  • Jerome Breton

    Thanks a lot for this article, this will help me a lot.

    By the way, you could use instead of WinSCP.exe, so that you will not have to user START /B and you can run any commands like a mode 200,90 for having a bigger console

  • I’m so glad that you wrote this up! I was just about to write the script myself when I thought maybe I’d google it first 🙂

    Funny, I went on the same quest you did in trying to find a way to monitor and sync a local directory to a remote directory. I discovered that while the actual syncing is something that can be done with a number of different tools ( I was sure that rsync would be the solution ) , I found that it was the ‘event monitoring’ that was kicking my butt. There is absolutely no easy way in windows to monitor a directory for changes and then trigger an event upon the change.

    When I started poking around in the WinSCP gui, and ‘rediscovered’ the ‘keep local directory up to date’ feature, I was thrilled. I was also too exhausted to script it (although I intended to , until now when I discovered your post. With the GUI, I’m always too afraid that I’ll set the destination directory incorrectly and wipe out my site ( the -delete option will do that if you are not careful). With the script, the destination path is hardcoded so less of a risk.

    BTW, working off of local files and using this method to sync beats the heck out of ExpanDrive or other solutions to map a ssh connection to a local drive. The speed can’t be beat. What finally drove me to abandon ExpanDrive was that committing to svn took 20 minutes to an hour. With local files its nearly immediate.

    Also, for those whose scripts are choking on the filemask paramater,  update WinSCP to at least 5.1.4 and you’ll have no issues.


    • Jordan Hopfner

      Glad you found it useful! I use it all the time, it’s quick, efficient and works amazing for testing. Just wish I would’ve figured it out sooner!

  • Mike Vassalotti

    Very well done. Truly outstanding post.