September 2, 2014

Moving Files In Linux - page 2

The Low Security Family

  • May 22, 2003
  • By Dee-Ann LeBlanc

The lftp tool can handle six different methods of file transfer (see the man page for the full list), including FTP and HTTP as well as the option of OpenSSL-based secure methods if they were included when the program was compiled. You can feed this tool instructions through a single command line, interactively, or even through a script file.

For an example, we'll teach lftp to grab the whole set of HOWTOs from the Linux Documentation Project's server. Since we're not psychic (or at least I'm not), we'll walk through by hand before trying to write a script or do a nice long command line, so start by typing:


As a result, you'll get the prompt:


lftp isn't actually sitting there connected to the server. There's no need to connect until you actually send a request. Now, if we type ls, we'll see a prompt saying that lftp is looking up the name and accessing the server, and then something similar to what's shown in Figure 1.

Rather than going through the tedious step by step of figuring out what directories to go to, we've all been through it with FTP, I've already looked to see where I want to go. I'll skip straight to the directory /pub/Linux/docs/HOWTO by typing cd /pub/Linux/docs/HOWTO. lftp connects for a moment to verify that the directory exists, and then changes to that directory.

Now, I don't want every HOWTO individually. I just want the .tar.bz2 file for the full HOWTO set, and after this I can have the cron program use lftp to see if there's a newer version available, and grab it. If I type ls *bz2 only one file is listed (the number will change according to the date):

lftp> ls *bz2

-rw-rw-r-- 1 gferg linux 5699858 Feb 27 05:00


I want to download this file to my ~/Downloads/documents directory, so I type lcd ~/Downloads/documents to change directories on my host machine:

lftp> lcd ~/Downloads

lcd ok, local cwd=/home/dee/Downloads


Now I type get Linux-HOWTOs-20030227.tar.bz2 and let lftp grab the first copy for me. Then I type exit to close the lftp prompt. After doing the walk-through like this, I could then turn around and write the necessary lftp script, and add it to my crontab scheduler.

This is where lftp is at its most useful, where you don't care if someone sniffs the content because you're just doing an anonymous FTP login and grabbing publicly accessible files. The moment you start needing to worry about passwords being sniffed, or file contents, then lftp isn't a good choice--unless you're using a version with OpenSSL compiled in and make sure to only use it for FTPS and HTTPS (secure) connections.

Sitemap | Contact Us