Borys Bradel's Blog
Synchronization through ftp
Tags: scripting August 11, 2008
One of the problems that I encountered while setting up this website was how to transfer files from my home computer to the website. At first, rsync seemed like a good approach. However, that is not allowed by the hosting site. Logging in through ftp and then transferring each file individually seemed too much of a hassle. Fortunately I found lftp, the sophisticated file transfer protocol, which is a great program that allows bulk transfers across ftp.
To copy files from a directory, x, on my home computer to a directory, y, on the website through host z with username abc, I use the following command: lftp -d -c 'open -e "mirror --newer-than='now-2hours' -R x y" -u abc z'
The syntax is somewhat convoluted and needs to be exactly right. -d indicates debug mode with extra printing, the -c indicates that there is exactly one command to execute, which is to open a connection to z. The open command takes one command indicated by -e that makes the files be mirrored. The remaining information is for the mirror command and can change. The mirror command is neat in that it can be used to only upload the most recently changed files instead of all the files. The structure of the lftp and open commands is important, and similar combinations don't work. You can find more information on the lftp website.
Copyright © 2008 Borys Bradel. All rights reserved. This post is only my possibly incorrect opinion.