Synching Files Between Remote PCs
I've been a big fan of all the life hacks sites and tutorials that have sprung up recently. In Danny O'Brien's original Life Hacks presentation, he mentioned file synchronization as one of the tools common to the most productive users. Prior to hearing that, I had tried several times to set up file synchronization between my home and work PCs and always ran into snags.
Thanks to inspiration from the Life Hacks presentation, I finally persevered. The result is a combination of four open source tools—copSSH, putty, Unison, and WinMerge—that allow me to quickly synchronize my files on a daily basis. I encountered quite a few road blocks in the process, which I will do my best to document here.
I've been using this setup successfully for months. I synchronize files once when I get to work and once before I leave and I'm able to work on all the same files, in the same directories, regardless of which PC I'm on. I can confirm that it has indeed been a productivity boon.
The SSH server I've found easiest to set up under Windows is copSSH. In fact, the setup process is easy enough that I feel comfortable skipping it in this tutorial and pointing you to the official installation instructions instead.
I set up copSSH on my main Windows box at home, then forwarded port 22 on my router to that machine.
You will also need to run the file synchronization component, Unison, on the remote machine in server mode. For the server side, I use the text-only version of Unison. The command line I use is:
unison-2.10.2d-win-text.exe -socket 412
I made a batch file containing the command above, which I then added to the Quick Launch bar.
To connect to the SSH server, you will need an SSH client, such as putty. Putty is easy to use, but you will also need to set up SSH tunneling in order to synchronize files via Unison.
Start by running putty and selecting the Tunnels category. For a source port, enter 6412. For the destination, you will need the IP address of your computer. If your home computer is behind a firewall, the IP address will probably be an address in the form of 192.168.x.x. Under destination, enter <ip address>:412. This forwards a free port on the local machine (6412) to the port used by Unison on the remote computer (412). Finally, click on the Add button to add.
Next, return to the Session category. Enter the Host Name (or IP address) of the router or machine you will be connecting to. For instance, if you are using a dynamic DNS service and a router at home, enter the host name associated with your router. For the purposes of this tutorial, I'm connecting directly between two machines on the same network.
Next, you will probably want to save the session, to avoid having to enter the tunneling information each time. Enter a name in the Saved Sessions box and click on the Save button.
Click on the Open button to establish a connection.
The first time you establish an SSH connection, you will be asked to confirm the server's fingerprint. Assuming that you've followed the steps correctly up to now, you should be connecting to your home computer, so simply click on Yes.
If you have problems with putty periodically disconnecting, try turning on keep alives under the Connections category. I use 300 seconds between keep alives.
The final step involves setting up Unison for synchronizing files. On the client side, I prefer to use the Unison GUI tool, rather than the text-only version.
In the directory containing the Windows binaries for Unison, look for the file called IMPORTANT.html, which will instruct you on how to download the GTK+ 2 for Windows component and add it to your path. If you neglect to complete both those steps, you will probably see an error message similar to the one below.
Once you have Unison running successfully, you will be prompted to enter a local directory to synchronize. As an example, you might use local directory called c:\ltemp.
The next screen prompts you for the information on the remote directory. Enter the name of the remote directory, such as c:\rtemp. On Unix systems, Unison is capable of handling the SSH connection itself. (At one point, I ran across some information on the Unison Yahoo Group for getting it to work under Windows, but it didn't seem to work for me.) For the purposes of this tutorial, we'll use a Socket connection to the localhost, using the port redirected earlier, 6412.
The first time you synchronize between the two directories, you will see the warning below. Click on the OK button and Unison will begin comparing the two directories.
The screen below shows the table Unison displays comparing the two directories. In this case, it shows two files in the remote directory that aren't yet in the local directory.
If you are comparing two relatively large Windows directories, Unison can be quite slow. To speed things up, there is a Windows-specific option called "fastcheck" for speedier file comparison. To enable it, you will need to edit the appropriate Unison preferences file. Each set of Unison directories stores a profile file (<profile>.prf) in the Unison profile directory, usually C:\Documents and Settings\<username>\.unison. Simply open the appropriate profile in a text editor and add a line containing:
fastcheck = yes
The Unison manual mentions a possible problem with Excel files when using fastcheck, but I haven't noticed it myself. To be on the safe side, I have two identical profiles, one with fastcheck on and one with it off and I run the "slow check" periodically, just in case.
Another useful profile command is ignore, which causes Unison to skip certain files or directories. For example, the following command is handy for skipping temporary files:
ignore = Name ~$*
I gave up on trying to get Diff to work under Windows. Instead, I configured a GUI merge utility called WinMerge, which also happens to be open source. If you accept the default file locations when installing WinMerge, adding the following line to a Unison profile file should call WinMerge:
merge = Regex .* -> "C:\PROGRA~1\WinMerge\WinMergeU.exe" "CURRENT1" "CURRENT2"