Skip to the examples.


If you’re not familiar with LFTP, it bills itself as a “sophisticated file transfer program”. It supports common protocols like FTP, HTTP/s, FXP, SFTP, and BitTorrent. It can also download multiple files in parallel, download one file as multiple segments in parallel, and resume a paused or canceled download. These capabilities make it particularly attractive to users of seedboxes, as the servers are generally geographically far from the user, with limited and or spotty connectivity.


If you’re on Linux, you should be able to find it in your distribution’s package repository. It’s also easily available on OS X via Homebrew. If neither of those work for you, the official site contains source code and rpm binaries. If you need LFTP for Windows, it appears to be readily available in Cygwin.

# Ubuntu / Debian
$ sudo apt install lftp

# Centos / RHEL / Fedora
$ sudo yum install lftp

# Mac OS X via Homebrew
$ brew install lftp

# Windows via Cygwin
# ( untested, please let me know if it works, )
> setup-x86_64.exe -q -N -n -d -D -s -P lftp


LFTP consists of a number of commands. It will give you an interactive shell to call these commands, like an FTP or shell session. You can also pass commands directly to it with no interactivity, more like rsync. Each of its commands does different things and takes different options. Some can be strung together to do great things, but unless you use it frequently you’ll never remember them. That’s why I wrote down these common example use cases so you can get going quickly:


Note: I’ve seen some other blogs that show how to setup an FTP server so you can download your files with it. If you have SSH access to the remote server, just use SFTP over SSH and save yourself the hassle and diminished security of running an FTP server.


  • Connect to a server via SSH, get dropped into an shell. LFTP will use SFTP over SSH so you don’t have to setup another server:


  • Connect to an FTP server with authentication, get dropped into an shell:
      $ lftp -p21 username


  • Connect to an HTTP/S server, get dropped into an shell.:
      $ lftp


Once you’re connected to the remote server, you can start transferring files:


  • Download a file with pget with continue support in 8 segments:
      pget -c -n 8 ./debian-6/debian-6.i386.iso


  • Mirror a directory using pget with continue support, 4 concurrent files and 8 concurrent segments per file:
      mirror -c -P 4 --use-pget-n=8 ./debian-6


  • Download multiple files with a glob expression, continue, pget, and 12 segments:
      glob -- pget -c -n 12 ./debian-6/*
  • Mirror multiple directories slected by a glob, using continue, pget for 12 segments, and mirror for 4 concurrent files:
      glob -d -- mirror -c -P 4 --use-pget-n=12 ./debian*


  • Download a torrent with lftp.
    $ lftp
     :~> torrent ./ubuntu-21.04-desktop-amd64.iso.torrent
    Name: ubuntu-21.04-desktop-amd64.iso
    dn:2.9G up:0 complete, ratio:0.00/0.00/0.00
    peers:17 connected:0 active:0 complete:0
    Seeding in background..



  • Upload a directory by reversing the mirror command:
      mirror -c --reverse ./remote_target ./local_source
  • Update a remote directory with mirror, removing (from the remote side) anything that’s been deleted locally:
      mirror -c --delete --reverse ./remote_target ./local_source


  • Upload a set of files based on a glob, with continue support, and 4 concurrent files. Note, if you’re transferring multiple files in a directory hierarchy, mirror is much easier to work with:
      mput -c  -P4 ./*.mp4


  • Execute some commands and keep the shell open with -e flag:
      $ lftp -e "cd A; pget A.txt; cd ../B; pget B.txt"
  • Execute a script file with -f flag:
      lftp -f ./script.lftp

Let’s look at a few other common use cases we can solve with scripts:


  • Our script downloads remote_dir to local_dir with mirror and pget (2 files, 4 segments, continue). This will not remove local files that are missing on the remote directory, so you can use this to accumulate files that live on your seedbox ephemerally:
      # script.lftp
      open sftp://
      mirror -c -P 2 --use-pget-n=4 ./remote_dir /mnt/local_dir


  • If you want to keep the local directory synced with the remote one, you can add the --delete flag to delete files locally when they’re deleted on the remote end. This is more useful if you’re using mirror to sync something like a website directory:
      # sync.lftp
      open sftp://
      mirror --delete -c -P 2 --use-pget-n=4 ./remote_dir /mnt/local_dir


  • If you lose your server or need to restore your website from an sync backup, you can use the --reverse for mirror to upload the files instead of downloading them. Note that using pget won’t make a difference here:
      # resore.lftp
      open sftp://
      mirror --reverse --delete -c ./remote_dir /mnt/local_dir

Get Password from Environtmental Variable

  • If you want to make your login password available to an lftp script through an environmental variable (without showing it to other users with ps), you can set the $LFTP_PASSWORD environmental variable and pass --env-password to your open command:
      export LFTP_PASSWORD=secretpassword
      # script.lftp
      open --env-password sftp://
      mirror --reverse --delete -c ./remote_dir /mnt/local_dir


I originally wrote most of this article as a sort of “cheat sheet” while I was working in an IT shop at UCSB. I wanted to preserve it here as I no longer work in that shop and would be bummed to lose the article. You can find it here if you want.