Recursive get with lftp

If you’re trying to figure out how to recursively download a directory with lftp, the wonderful command-line FTP and SFTP client, this is what you want:

mirror <directory>

… and that’s that. Hopefully this will be more helpful to someone than the current Google documentation results. 😉

Update: Thanks to molok in the comments, here’s how you upload recursively:

mirror -R <directory>
This entry was posted in General and tagged , , , , , , . Bookmark the permalink.

17 Responses to Recursive get with lftp

  1. Garrett says:

    I love lftp. It’s great.

    I use mget all the time, and mirror is really useful as you suggest.

    As a related tip: Did you know you can use lftp on http as well? It understands directory indexing (such as Apache’s) and presents it in the simple lftp interface we all know and love.

  2. Andre Pang says:

    lftp: the zsh of ftp clients. Fucken’ A man.

  3. molok says:

    and ‘mirror -R’ to upload a directory… awesome.

  4. Domas says:

    At least in Debian you need to use lftp -e mirror for mirroring remote site.

  5. Jeff Waugh says:

    @Domas: Thanks, I’ve updated the post so it doesn’t suggest direct shell use.

  6. Don says:

    its annoying that you cant do a glob on a directory like:

    > mirror Foobar.*

  7. Dan says:


    Well lemme take that “Glen, you’re awesome” comment back. Simply because i thoughed “glob -d mirror Foobar.*” would actually work on dirs. Which it does NOT.

    So what i’m really looking for is a way to mirror everydir containing a certain word. “glob -d mirror *Foobar” only mirrored the FIRST dir matching “Foobar”. 🙁

    Any ideas?

  8. herbs says:

    Thanks Jeff – I always wondered how to get the whole bunch with the subdirectories over.

  9. n2j3 says:

    mirror --use-pget-n=5
    to employ lftp’s much vaunted multiple connection mode (and seriously speed up transfer)

  10. Battaglin says:

    first.. great post
    got this one little problem when using mirror to backup stuff

    lftp -u username,password -e “mirror –delete –only-newer –verbose path/to/source_directory path/to/target_directory” ftpsite

    if I use this in a .sh and want lftp to exit after..what to do? I think I’ve tried almost everything from the lftp man. -f or -c as suggested dont work at all 🙁

    • juan frankenstein says:

      just add the quit to your -e string

      lftp -u username,password -e “mirror –delete –only-newer –verbose path/to/source_directory path/to/target_directory;quit” ftpsite

  11. Lucas says:

    Thanks for the post and let me know about “mirror”.

    I’m learning to use lftp (It’s great) to synchronize multiple directories (from 2 different computers) throw an ftp server.

    I’m doing something like this to upload:
    > open
    > mirror -R -v –only-newer –delete –verbose /home/source /destination

    and the same, without -R to download my files. It works great, but how can I upload and download multiple directories at once, I mean, instead of:
    > open
    > mirror -R -v –only-newer –delete –verbose /home/source-1 /destination
    > mirror -R -v –only-newer –delete –verbose /home/source-2 /destination
    > mirror -R -v –only-newer –delete –verbose /home/source-3 /destination
    > mirror -R -v –only-newer –delete –verbose /home/source-n /destination

  12. Steve says:

    Looks like

    mirror -R

    isn’t recursive it’s reverse!!!


Leave a Reply

Your email address will not be published. Required fields are marked *

Comments will be sent to the moderation queue.