, 1 min read

Copy Directories to FTP-Server

Sometimes you have to copy whole directories recursively to an FTP-server. Many FTP servers are not able to handle bulk uploads directly. Here lftp comes to the rescue. lftp allows to upload or download entire directories irrespective of the capabilities of the FTP server.

Assume we want to upload our entire blog to a remote FTP server.

lftp -u User,password some-ftp-server.com
set ssl:verify-certificate false
mirror -R blog

Certificate handling (set ssl:verify-certificate false) is only necessary if lftp complains about "Fatal error: Certificate verification: Not trusted".

mirror -R is the command to copy from local to remote.

lftp honors entries in ~/.netrc. An entry in .netrc looks like this:

machine some-ftp-server.com login YourUserName password YourPassword

lftp has the following commands:

help
    !<shell-command>                     (commands)
    alias [<name> [<value>]]             attach [PID]
    bookmark [SUBCMD]                    cache [SUBCMD]
    cat [-b] <files>                     cd <rdir>
    chmod [OPTS] mode file...            close [-a]
    [re]cls [opts] [path/][pattern]      debug [OPTS] [<level>|off]
    du [options] <dirs>                  edit [OPTS] <file>
    exit [<code>|bg]                     get [OPTS] <rfile> [-o <lfile>]
    glob [OPTS] <cmd> <args>             help [<cmd>]
    history -w file|-r file|-c|-l [cnt]  jobs [-v] [<job_no...>]
    kill all|<job_no>                    lcd <ldir>
    lftp [OPTS] <site>                   ln [-s] <file1> <file2>
    ls [<args>]                          mget [OPTS] <files>
    mirror [OPTS] [remote [local]]       mkdir [OPTS] <dirs>
    module name [args]                   more <files>
    mput [OPTS] <files>                  mrm <files>
    mv <file1> <file2>                   mmv [OPTS] <files> <target-dir>
    [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>
    torrent [OPTS] <file|URL>...         user <user|URL> [<pass>]
    wait [<jobno>]                       zcat <files>
    zmore <files>