Home | Hardware | Internet News |Web Hosting |IT Management |Network Storage
LinuxPlanet
Search 
  Power Search | Tips 

 Front Door
 Discussion
 LinuxEngine
 Opinions
 Reports
 Reviews
 Tutorials
 News
 Technology Jobs

 Browse by subject.
Free Newsletter

Linux Planet
Linux Today
More Free Newsletters

Be a Commerce Partner


















internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Print this article
Email this article

   LinuxPlanet / Tutorials







Moving Files In Linux
lftp

Dee-Ann LeBlanc
Thursday, May 22, 2003 09:49:23 AM

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:

lftp www.tldp.org

As a result, you'll get the prompt:


lftp www.tldp.org:~>

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 www.tldp.org:/pub/Linux/docs/HOWTO> ls *bz2

-rw-rw-r-- 1 gferg linux 5699858 Feb 27 05:00
Linux-HOWTOs-20030227.tar.bz2

lftp www.tldp.org:/pub/Linux/docs/HOWTO>

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 www.tldp.org:/pub/Linux/docs/HOWTO> lcd ~/Downloads

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

lftp www.tldp.org:/pub/Linux/docs/HOWTO>

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.

Next: rcp »

Skip Ahead

1 The Low Security Family
2 lftp
3 rcp
4 rsync
5 wget
6 The High Security Family
7 scp
8 sftp
9 Wrapping Up
Figure 1. When we run a command in lftp that needs to reach out to the Internet, it gets the information it needs and then disconnects, waiting for the next command.
Figure 1. When we run a command in lftp that needs to reach out to the Internet, it gets the information it needs and then disconnects, waiting for the next command.





Linux is a trademark of Linus Torvalds.


internet.com home | search | help! | about us

Jupiter Online Media

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers