[Update: this post discusses some outdated techniques, please see this newer post for a better technique to use ssh with unison on windows]
I’m running windows vista on a laptop, and need to synchronize files with a linux server (for a web development project). After googling for a while, I found two options: rsync and unison. rsync requires cygwin, and it’s for (uni-directional) mirroring. unison on the other hand does not require cygwin, and is designed for (bi-directional) synchronization. so I chose unison.
Unison seems easy enough to use, check out the tutorial on its manual page.
but I quickly discovered that it doesn’t really work on windows out of the box: it needs “ssh”, or an ssh-like tool to be present on the machine, and guess what, ssh requires cygwin!
Now, there’s “plink” which behaves pretty much like ssh, except for some subtle differences, but these “subtle” differences render it unusable with unison. The problem is that unison sends some command-line options to ssh that plink can’t understand.
I found this discussion page on google, and a solution is offered in the form of a bat file that removes the extra command-line arguments before passing the rest to plink
So you can save this file somewhere and use the -sshcmd option to make unison use this file as if it was “ssh”.
A problem arises when you connect to the server and you are prompted to enter your password: unison chocks and says “the ssh server is responding with something that I don’t understand, so I’ll quit”!! You’d expect a program that’s designed to connect to ssh servers and sync files with them to be smart enough to handle the password prompt; but then again, we’re using plink, where as unison expects “ssh”, and I guess this is also one of the “subtle” differences between ssh and plink.
so as a way around that we could pass the password on the command line using -sshargs option.
see, plink has this option “-pw password” which has the nice effect of allowing you to bypass the “password prompt”, and we can use it for this purpose. pass this to unison:
-sshargs “-pw password”
and it should do the trick (you need the quotes ..)
of course when you automate this, it raises the issue of having your password stored somewhere in a text file on your laptop; so you have to watch out and make sure no unauthorized person can read this file.
Now, if you actually google “window unison ssh”, you will see this page http://www.wischik.com/lu/programmer/unison-ssh.html
which provides a nice tool (conveniently named “ssh.exe”) that you can copy to a folder that’s included in your PATH environment variable, but it still suffers from a problem with the password prompt: the prmopt is broken; it doesn’t work (at least on my vista laptop), as soon as you type the first character, it presses enter for you and prompts you to enter the password again because the password that you just entered is incorrect :) (maybe this only happens in vista, but it happens for me, and that’s what matters).
Now, there’s another dependency that you will probably need: diff, as unison uses it (optionally) to show the differences between files. So you might consider downloading it if you don’t already have it.