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.

  1. $ lftp
  2. lftp :~> o ftp.servername.com
  3. lftp ftp.servername.com:~> user USERNAMEHERE
  4. Password: PASSWORD HERE

this much is like the old ftp command.

To upload the whole folder to the remove server

  1. 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.

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

or more information on mirror command inside lftp

  1. lftp :~> help mirror
  2. Usage: mirror [OPTS] [remote [local]]
  3.  
  4. Mirror specified remote directory to local directory
  5.  
  6. -c, --continue continue a mirror job if possible
  7. -e, --delete delete files not present at remote site
  8. --delete-first delete old files before transferring new ones
  9. -s, --allow-suid set suid/sgid bits according to remote site
  10. --allow-chown try to set owner and group on files
  11. --ignore-time ignore time when deciding whether to download
  12. -n, --only-newer download only newer files (-c won't work)
  13. -r, --no-recursion don't go to subdirectories
  14. -p, --no-perms don't set file permissions
  15. --no-umask don't apply umask to file modes
  16. -R, --reverse reverse mirror (put files)
  17. -L, --dereference download symbolic links as files
  18. -N, --newer-than=SPEC download only files newer than specified time
  19. -P, --parallel[=N] download N files in parallel
  20. -i RX, --include RX include matching files
  21. -x RX, --exclude RX exclude matching files
  22. RX is extended regular expression
  23. -v, --verbose[=N] verbose operation
  24. --log=FILE write lftp commands being executed to FILE
  25. --script=FILE write lftp commands to FILE, but don't execute them
  26. --just-print, --dry-run same as --script=-
  27.  
  28. When using -R, the first directory is local and the second is remote.
  29. If the second directory is omitted, basename of first directory is used.
  30. 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

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Easily link to terms in various wikis. For help, see <a href="/interwiki/1">interwiki</a>.

More information about formatting options