LFTP - Linux Automatic FTP

LFTP - Linux Automatic FTP






Note

We are no longer accepting new customers or work orders at this time. Thank you for your interest.


The Problem

Do you need to access a client's web site files via FTP so frequently, and wish you had a way of automatically connecting to it from the Linux command line?

Wouldn't it be nice to have a command that logged you in with the password, "cd"ed to the right directory, before giving you the FTP prompt?

Have you ever gotten mad at the regular "ftp" command because of its serious limitations, having been written in the 1980s?

The Solution

There's a good replacement for regular FTP - the "lftp" command. Many Linux distros come with it built-in, like RedHat and CentOS 5.

The LFTP Command

Example command:

lftp -u username,password -e "cd htmldir" www.domainname.com

This command automatically logs you in with the given "username" and "password". With some hosting sites, the "username" looks like an email address, like "person@domainname.com". That works fine on the command line:

Simplify The Command

But who wants to remember all that, and have to type it everytime? Once you get the command just right and it logs you in and everything, you can create a shell variable, or put it in an alias in the C-shell.

For example (TCSH):

alias dftp 'lftp -u username,password -e "cd htmldir" www.domainname.com'

This alias gives you a new command, now you can just type "dftp" and that whole long command will be run. If you want this alias set up for you every time, add it to the bottom of your .tcshrc or .cshrc file in your home directory.

Once you're logged in, you'll be at lftp's normal command prompt. All the usual FTP commands work -- cd, pwd, lcd, lpwd, get, put, mput *, ...

You don't have to type "prompt" to get the inter-file prompting to turn off, it's already turned off by default.

To break out of an LFTP session without losing the connection, type the "su" command. That suspends the command, gives you back your shell prompt. You can see it waiting for you with the "jobs" shell command. You can resume it with the "fg" shell command.

For long-term editing sessions with customer web site projects sometimes I need to stay logged in for days. LFTP automatically reconnects me on lost or timed-out connections. What I usually do is run a "screen" session, and run "lftp" within that. Now, even if I'm disconnected from the linux server, nothing is lost. I can SSH back in (from any computer anywhere), type "screen -d -r" to disconnect and reconnect to my screen sessions. Everything that was on the screen before is redrawn, any suspended processes are still there waiting for me like open editing sessions and lftp!

Conclusion

If you have to do work remotely on a Linux/Unix server, I highly recommend playing with the commands "screen" and "lftp". They're both all text-oriented, so they work in any remote-login kind of environment from anywhere. Low bandwidth connections are fine, since text transmits way faster than bitmaps of screen images.

You can learn more about them with the command "man screen" and "man lftp", or you can download the source code for them from the Internet (open source - freely available), compile and install them for your particular system.



Bookmark and Share


Don't miss the latest web tips and tricks!
Subscribe to our low-volume mailing list:

Privacy Policy

See other tricks:  Web/PHP | Unix/Linux | Perl | SQL | General


Sample Sites | Customers | Our Team | Contact Us | Tips and Tricks | Tools | Our Network | Home

Copyright © 2006 - 2010 Keith Smith Internet Marketing LLC, all rights reserved.
Problem with this web site? please let us know