Downloading whole directory with FTP
It seems that it is not possible to download or upload folders using the ftp command. Until now I have been using FileZilla, the GUI ftp client for most of my ftp works. Well GUI is GUI and is not always available.
Turns out, there is this awesome lftp command that does the job pretty well. It is like the bash shell but for ftp with lots of tricks up its sleeve. It even does a remote auto completion, awesome.
$ lftp lftp :~> o ftp.servername.com lftp ftp.servername.com:~> user USERNAMEHERE Password: PASSWORD HERE
this much is like the old ftp command.
To upload the whole folder to the remove server
lftp :~> mirror -R /path/to/local/folder /path/to/remote/folder
by default, mirror command downloads files from remote source folder to local folder. Option -R means reverse the process where by, instead of downloading, it uploads the local/folder to remote/folder location.
Getting help is straight forward with the help command.
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]
or more information on mirror command inside lftp
lftp :~> help mirror Usage: mirror [OPTS] [remote [local]] Mirror specified remote directory to local directory -c, --continue continue a mirror job if possible -e, --delete delete files not present at remote site --delete-first delete old files before transferring new ones -s, --allow-suid set suid/sgid bits according to remote site --allow-chown try to set owner and group on files --ignore-time ignore time when deciding whether to download -n, --only-newer download only newer files (-c won't work) -r, --no-recursion don't go to subdirectories -p, --no-perms don't set file permissions --no-umask don't apply umask to file modes -R, --reverse reverse mirror (put files) -L, --dereference download symbolic links as files -N, --newer-than=SPEC download only files newer than specified time -P, --parallel[=N] download N files in parallel -i RX, --include RX include matching files -x RX, --exclude RX exclude matching files RX is extended regular expression -v, --verbose[=N] verbose operation --log=FILE write lftp commands being executed to FILE --script=FILE write lftp commands to FILE, but don't execute them --just-print, --dry-run same as --script=- When using -R, the first directory is local and the second is remote. If the second directory is omitted, basename of first directory is used. If both directories are omitted, current local and remote directories are used.
Its great to have the full power of GUI FTP-client on console once again.


Comments
Very useful information!
Post new comment