Unix: Flexibly moving files with lftp

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


My ~/.lftprc file now looks like this:

set ftp:ssl-protect-data true
set ftps:initial-prot
set ftp:ssl-force true
set ftp:ssl-protect-data true
set ssl:verify-certificate off

This gives me encrypted connections to the server when I type lftp ftp.targetsite.com.

Using lftp

You can launch lftp by typing just lftp and then using an open command to take you to your target site or you can provide the target's name on the same line as lftp like I did.

$ lftp ftp.targetsite.com


$ lftp
lftp :~> open ftp.targetsite.com

Once you log in, you can list files and use get, mget, put etc. commands as needed:

$ lftp
lftp :~> open ftp.targetsite.com
lftp ftp.targetsite.com:~> user sandrahs NotMyRealPassword
lftp sandrahs@ftp.targetsite.com:~> ls

If you ask for help, you're likely to see something like this, showing all the commands that are available to you:

lftp :~> help
    !<shell-command>                    (commands)
    alias [<name> [<value>]]            anon
    bookmark [SUBCMD]                   cache [SUBCMD]
    cat [-b] <files>                    cd <rdir>
    chmod [OPTS] mode file...           close [-a]
    [re]cls [opts] [path/][pattern]     debug [<level>|off] [-o <file>]
    du [options] <dirs>                 exit [<code>|bg]
    get [OPTS] <rfile> [-o <lfile>]     glob [OPTS] <cmd> <args>
    help [<cmd>]                        jobs [-v]
    kill all|<job_no>                   lcd <ldir>
    lftp [OPTS] <site>                  ls [<args>]
    mget [OPTS] <files>                 mirror [OPTS] [remote [local]]
    mkdir [-p] <dirs>                   module name [args]
    more <files>                        mput [OPTS] <files>
    mrm <files>                         mv <file1> <file2>
    [re]nlist [<args>]                  open [OPTS] <site>
    pget [OPTS] <rfile> [-o <lfile>]    put [OPTS] <lfile> [-o <rfile>]
    pwd [-p]                            queue [OPTS] [<cmd>]
    quote <cmd>                         repeat [OPTS] [delay] [command]
    rm [-r] [-f] <files>                rmdir [-f] <dirs>
    scache [<session_no>]               set [OPT] [<var> [<val>]]
    site <site_cmd>                     source <file>
    user <user|URL> [<pass>]            version
    wait [<jobno>]                      zcat <files>
    zmore <files>                       history -w file|-r file|-c|-l [cnt]

If you want to download an entire directory, you can use the mirror command.

Photo Credit: 

flickr / hbp_pix

Join us:






Operating SystemsWhite Papers & Webcasts

See more White Papers | Webcasts

Answers - Powered by ITworld

Ask a Question