rsync, lftp and exclude lists

When it comes to synchronizing stuff with a remote server, most people will use either rsync or ftp for file transfers. I personally prefer rsync, where the upload command would look something like this:

rsync -e ssh -avz --exclude-from 'exclude-list.txt' /path/to/local/dir

I find rsync's --exclude-from option really helpful and much more convenient to use than multiple --exclude switches since you can keep all your filenames and patterns in one place. However, you may not have a possibility to use rsync at all, especially if you're using a cheap shared hosting.

That was my case yesterday, so I searched for an ftp alternative to rsync and stumbled upon lftp in this post. It looked really nice until I found out lftp doesn't support exclude lists, which means you can't make it read exclude patterns from a file. The good news is, lftp does allow you to specify multiple --exclude switches at once, so I modified the command to make use of my exclude-list.txt like this:

lftp -u username,password -e "mirror --only-newer sed 's/^/--exclude /' exclude-list.txt | tr 'n' ' ' --reverse /path/to/local/dir /path/to/public_html"

This way, sed prepends every line with an --exclude switch and tr replaces newlines so in the end we have our lftp mirror command with all necessary excludes in it. Well, a bit later I realized this hosting sucked and changed to a different one with ssh and rsync, but that's a different story.