Unix: Flexibly moving files with lftp

Moving files between Linux (and other) servers is a lot smarter and more versatile when you discover lftp.


What is lftp?

Some sites -- and even the man page -- claim that "lftp" stands for "sophisticated file transfer program", but I'm still struggling with that one. I might have suggested "limber ftp", "lithe ftp", even "liberal ftp", but someone decided that the "l" could stand for "sophisticated", so who am I to question their logic?

A more important question is "How has it escaped my attention until now?". Maybe because I pretty much stopped using ftp commands years ago in favor of scp. Maybe simply because no one brought this tool to my attention -- until now. But lftp is hardly new (it initially showed up in 1996, but wasn't called lftp until 1997) and its flexibility takes it way beyond what anyone would expect of an ftp program.

Yes, lftp has a lot of interesting features and just got shoved in front of my face when a vendor I deal with changed their download options to be more secure. Using lftp from a Unix command line was one of the choices presented to me going forward. So exactly what is lftp and why it is so much worth using and understanding?

For one thing, lftp doesn't just support ftp. It also supports many access methods including FTP, HTTP, FISH, SFTP, HTTPS and FTPS. And it can download an entire website if you do a recursive get with the tool's mirror command.

The command also has a great handle on reliability. Non-fatal errors are ignored and operations restarted as needed. My first impression was that it's a solid tool and performs very well.

With lftp, you can launch commands in parallel by putting them in the background much as we do on the Unix/Linux command line using & and you can group commands within parentheses and run the whole group in background. To move a running job into the background, just use ^z. You can then bring it back into the foreground with fg. How cool is that? And a jobs command is available to list running jobs.

If some of your jobs haven't completed when you exit lftp, lftp will put itself in nohup (no hangup) mode in the background to complete them.

That's a lot to get from anything that calls itself an ftp program.

Configuring lftp

What I needed to do was run a series of set commands to prepare my lftp session to work with the server that I needed to grab files from. Fortunately, I quickly determined that I didn't need to type these commands every time I went to the site for updates. Instead, I could drop the needed commands into either a global configuration file (good choice if other accounts on the server would need the same setup) or into a dot file in my personal account (~/.lftprc or ~/.lftp/rc).

Photo Credit: 

flickr / hbp_pix

Join us:






Answers - Powered by ITworld

ITworld Answers helps you solve problems and share expertise. Ask a question or take a crack at answering the new questions below.

Ask a Question