Lftp file transfers for Unix

Last modified by Mélodie on 2026/04/01 13:56

lftp manual

lftp is a command-line file transfer program. It is powerful and reliable, and very useful in the context of remote server management. It supports FTP, HTTP, FISH, SFTP, HTTPS and FTPS protocols.

It comes with a configuration file /etc/lftp.conf that can be used as a base for customization. It contains many commented examples.

The personal configuration file must be created under $HOME/.config/lftp/. Here is an example of a customized lftp.conf file:

# For more options check the comments in the /etc/lftp.conf file
# set ftp:ssl-allow false
# set xfer:clobber "on"
set ssl:verify-certificate no
set ftp:ssl-force yes
set ftp:anon-pass "mozilla@"

Official documentation can be found at https://lftp.yar.ru/

Basic Commands

FTP

  • lftp <ftp://login@ip>                       # connection to the server root
  • lftp <ftp://login@ip:/target-directory>     # direct connection to destination directory
  • lftp <ftp://login@ip/target-directory>      # same without the ':' sign

The password is requested interactively after connection.

SFTP

Same as above, but with lftp sftp://…

Navigation and information commands

  • pwd                       # displays the current directory (remote)
  • lpwd                      # displays the current directory (local)
  • ls                        # lists remote files
  • lcd                       # displays the current local directory while trying to change the local directory
  • !ls                       # lists local files (! = local execution)
  • cd directory              # changes remote directory
  • lcd directory             # changes local directory

File transfers

  • get <file>                    # downloads the chosen remote file to the current local directory
  • get <file> -o /local/path/    # downloads the chosen remote file to a specific local directory
  • put <file>                    # sends the chosen local file to the current remote directory
  • mget <file1 file2 file3…>     # downloads several chosen files to the current local directory
  • mput <file1 file2 file3…>     # sends several chosen files to the current remote directory

Complete directory transfers

Connected to the server:

  • lftp login@server:/directory> mirror <remote-folder> <local-folder/>             # downloads a complete directory to the current local directory
  • lftp login@server:/directory> mirror --reverse <local-folder/> <remote-folder>   # sends the content of a complete local directory to the remote server
  • lftp login@server:/directory> mirror --reverse <local-folder> <remote-folder>    # sends a complete local directory to the remote server
  • mirror --continue         # resumes an interrupted transfer
  • mirror --delete           # deletes at the destination what no longer exists at the source
  • mirror --parallel=4       # parallel transfers

Parallel transfers

--parallel=N launches N transfers simultaneously instead of only one at a time. Useful for directories with many small files — instead of waiting for each file to finish before moving to the next, lftp transfers several at the same time.

Connected to the server:

lftp login@server:/directory> mirror --parallel=4 <remote-folder/> <local-folder/>

=> the prompt is blocked until the end of the transfer.

In interactive lftp, launch a mirror in the background:

lftp login@server:/directory> mirror --parallel=4 <remote-folder/> <local-folder/> &

=> with the '&' sign the prompt returns immediately, the transfer continues in the background. You can continue typing commands as needed.

Miscellaneous

  • jobs         # displays current transfers
  • wait         # waits for current transfers to finish
  • queue        # puts commands in a queue
  • exit / quit  # exits lftp

Miscellaneous — practical use

jobs, wait and queue are useful when launching a background transfer from the lftp prompt, to continue navigating in the meantime:

  • jobs # see the status of the current transfer
  • wait # block until the transfer is finished

queue allows to chain commands that will execute one after another:

  • queue mirror /dir1/ /dest1/
  • queue mirror /dir2/ /dest2/
  • queue mirror /dir3/ /dest3/
  • wait

Lftp executes the three mirrors sequentially without intervention.

Put each queue in the background if you don't want to use "wait":

  • queue mirror /dir1/ /dest1/ &
  • queue mirror /dir2/ /dest2/ &
  • queue mirror /dir3/ /dest3/ &

/!\ here the three run in parallel simultaneously: if the three destinations are on the same server, there is a risk of saturating the connection and/or refusal from the FTP server /!\

=> wait after queues is recommended in case of transfers to the same server.

Complete directory transfers — syntax and options

From the lftp prompt, already connected to the source server:

mirror source-directory/ /local/path/destination-directory/

or

mirror source-directory /local/path/

=> The presence of the final slash / determines the result

Keep in mind for reading the following examples:

  • With source-directory/ the content of the directory is copied to the destination, but not the directory itself.
  • With source-directory the complete directory is copied to the destination, content included.
  • The ~/ sign for "home" should be adapted according to your case
  • Always prefer moving into the working directory, whether it is local or remote

From the bash terminal, not connected, retrieves the complete content of the remote directory:

lftp -e "mirror <sftp://login:password@server:/source-directory/> /local-directory/destination/ ; quit"

Options

  • --reverse : reverses the direction of the transfer: sends from local to remote

Ex : mirror --reverse ~/local-directory/ remote-directory/

  • --continue : resumes an interrupted transfer, only re-transfers what is missing or has been modified

Ex : mirror --continue ~/source-directory/ /local-directory/destination/

  • --delete : deletes at the destination files that no longer exist at the source — use with caution

Ex : mirror --delete ~/source-directory/ /local-directory/destination/

  • --parallel=N : launches N transfers simultaneously — useful for directories containing many small files

Ex : mirror --parallel=4 ~/source-directory/ /local-directory/destination/

  • --verbose : displays each file transferred as it goes

Ex : mirror --verbose ~/source-directory/ /local-directory/destination/

  • --log=file.log : records the operations performed in a file: /!\ does not capture errors (use 2>&1 redirection for that) /!\

Ex : mirror --log=transfert.log ~/source-directory/ /local-directory/destination/

Mirroring between two remote servers

Direct transfer from one server to another, without going through the local machine. The command is written in a single line from the bash terminal, with the two complete URIs — the first argument is the source, the second is the destination:

lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> ; quit"

Source and destination protocols can be different (sftp, ftp, ftps) — lftp handles the conversion transparently.

/!\ Passwords appear in plain text in the command line /!\

To avoid recording in the bash history, prefix the command with a space. This requires HISTCONTROL to be set to ignorespace or ignoreboth:

lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> ; quit"

=> The final slash on both URIs is important: it ensures that the content of the source directory goes into the destination directory, rather than the source directory being recreated inside.

=> Difference between ; quit and && quit:

  • ; quit : exits in all cases at the end of the transfer
  • && quit : only exits if the mirror finished without error

=> Without --delete, the mirror is additive: it does not erase anything at the destination.

=> To capture errors in a log file, redirect stdout and stderr:

lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> && quit" > transfert.log 2>&1

Quit the connection

lftp login@server:/directory> bye

or quit or exit


/!\ Detail: The man page does not mention bye, it only documents exit and quit implicitly via "ftp:use-quit".

What the man page says about exit: if jobs are running in the background, exit detaches lftp from the terminal and lets it continue in the background (similar behaviour to nohup) rather than killing everything: transfers continue.

Furthermore exit kill forces all jobs to stop before quitting.

Needs verification: bye could be an alias of exit or quit inherited from FTP tradition (FTP servers often reply bye upon disconnection), but the man page does not mention it.