22 November, 2009

Windows to Linux file synchronization over ssh: Unison solution

The aim: Portable and simple solution (no administrative right required on both sides) to synchronize files from Windows to Linux machine over insecure network (trough ssh) using Unison (ie. using only freeware software).
The problems: There is no ssh command line client in Windows.

Here are the important details:
I have used Unison (version 2.32.52), runtime GTK+ 2.14.7a environment from the Pidgin project (as described on the unison's page), plink.exe (version 0.60) and small script to point unison's sshcmd to plink.exe.

1) Create a new folder and unpack the two executable from Unison ("Unison" in my case).

2) As user install GTK somewhere.
- add the c:\somewhere\GTK\2.0\bin to the PATH variable in the system settings.
- or copy all files from \GTK\2.0\bin to the Unison folder. Then copy the whole (not the content) "etc", "lib" and "share" folders as well in the same folder.
3) Download and copy plink.exe in the "Unison" folder.

4) In notepad copy paste the following line
@c:\pathtoputty\plink.exe -ssh -P 22 -pw [mypassword] -l [myusername] -load [myputtysavedsession] "unison -server -auto"
change to fit your configuration and save it as "plinker.bat" in the "Unison" folder.
If you use pagent from the PuTTY then you can omit the username and password and use ssh-keys as usual (then also your password will be safe)

5) On the linux computer download or install unison. It will be good if you match the version on the Windows machine or vice versa. If you download the static binary, put it somewhere in your $PATH.

6) Start the Unison Gui version and configure your profile. This will fail, because ssh is not specified. Go to C:\Documents and Settings\yourprofile\.unison and add this line to the profile you have created.
sshcmd = plinker.bat
This and the GTK assumes that you have started Unison from its folder.

6) Start again - this time it should work. Enjoy.

Note: In point 4 you might need to provide the full path to the unison binary on the Linux machine.
Note: Since the configuration for the server address is actually specified in "plinker.bat" (it actually overrides the address specified in unison) you will need another script to connect to another server.

The original idea for the plinker.bat script is taken from here.

No comments: