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

Hide last authors
Mélodie 4.1 1 # lftp manual
Mélodie 1.1 2
Mélodie 4.1 3 **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.
Mélodie 1.1 4
Mélodie 4.1 5 It comes with a configuration file /etc/lftp.conf that can be used as a base for customization. It contains many commented examples.
Mélodie 1.1 6
Mélodie 4.1 7 The personal configuration file must be created under `$HOME/.config/lftp/`. Here is an example of a customized lftp.conf file:
Mélodie 1.1 8
9 ```
Mélodie 4.1 10 # For more options check the comments in the /etc/lftp.conf file
Mélodie 1.1 11 # set ftp:ssl-allow false
12 # set xfer:clobber "on"
13 set ssl:verify-certificate no
14 set ftp:ssl-force yes
15 set ftp:anon-pass "mozilla@"
16 ```
17
Mélodie 4.1 18 Official documentation can be found at <https://lftp.yar.ru/>
Mélodie 1.1 19
Mélodie 4.1 20 # Basic Commands
Mélodie 2.1 21
Mélodie 1.1 22 ## FTP
23
Mélodie 4.1 24 * `lftp <ftp://login@ip>` # connection to the server root
25 * `lftp <ftp://login@ip:/target-directory>` # direct connection to destination directory
26 * `lftp <ftp://login@ip/target-directory>` # same without the ':' sign
Mélodie 2.2 27
Mélodie 4.1 28 The password is requested interactively after connection.
Mélodie 1.1 29
30 ## SFTP
31
Mélodie 4.1 32 Same as above, but with `lftp sftp://…`
Mélodie 1.1 33
Mélodie 4.1 34 ## Navigation and information commands
Mélodie 2.1 35
Mélodie 4.1 36 * `pwd` # displays the current directory (remote)
37 * `lpwd` # displays the current directory (local)
38 * `ls` # lists remote files
39 * `lcd` # displays the current local directory while trying to change the local directory
40 * `!ls` # lists local files (! = local execution)
41 * `cd directory` # changes remote directory
42 * `lcd directory` # changes local directory
Mélodie 1.1 43
Mélodie 4.1 44 ## File transfers
Mélodie 2.17 45
Mélodie 4.1 46 * `get <file>` # downloads the chosen remote file to the current local directory
47 * `get <file> -o /local/path/` # downloads the chosen remote file to a specific local directory
48 * `put <file>` # sends the chosen local file to the current remote directory
49 * `mget <file1 file2 file3…>` # downloads several chosen files to the current local directory
50 * `mput <file1 file2 file3…>` # sends several chosen files to the current remote directory
Mélodie 2.1 51
Mélodie 4.1 52 ## Complete directory transfers
Mélodie 1.1 53
Mélodie 4.1 54 Connected to the server:
Mélodie 2.8 55
Mélodie 4.1 56 * `lftp login@server:/directory> mirror <remote-folder> <local-folder/>` # downloads a complete directory to the current local directory
57 * `lftp login@server:/directory> mirror --reverse <local-folder/> <remote-folder>` # sends the content of a complete local directory to the remote server
58 * `lftp login@server:/directory> mirror --reverse <local-folder> <remote-folder>` # sends a complete local directory to the remote server
Mélodie 1.1 59
Mélodie 4.1 60 * `mirror --continue` # resumes an interrupted transfer
61 * `mirror --delete` # deletes at the destination what no longer exists at the source
62 * `mirror --parallel=4` # parallel transfers
Mélodie 1.1 63
Mélodie 4.1 64 ### Parallel transfers
Mélodie 2.30 65
Mélodie 4.1 66 --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.
Mélodie 2.22 67
Mélodie 4.1 68 Connected to the server:
Mélodie 2.22 69
Mélodie 4.1 70 lftp login@server:/directory> mirror --parallel=4 <remote-folder/> <local-folder/>
Mélodie 1.1 71
Mélodie 4.1 72 => the prompt is blocked until the end of the transfer.
Mélodie 2.1 73
Mélodie 4.1 74 In interactive lftp, launch a mirror in the background:
Mélodie 1.1 75
Mélodie 4.1 76 lftp login@server:/directory> mirror --parallel=4 <remote-folder/> <local-folder/> &
Mélodie 1.1 77
Mélodie 4.1 78 => with the '&' sign the prompt returns immediately, the transfer continues in the background. You can continue typing commands as needed.
Mélodie 1.1 79
Mélodie 4.1 80 ## Miscellaneous
Mélodie 1.1 81
Mélodie 4.1 82 * `jobs` # displays current transfers
83 * `wait` # waits for current transfers to finish
84 * `queue` # puts commands in a queue
85 * `exit / quit` # exits lftp
Mélodie 1.1 86
Mélodie 4.1 87 ### Miscellaneous — practical use
Mélodie 2.1 88
Mélodie 4.1 89 _jobs_, _wait_ and _queue_ are useful when launching a background transfer from the lftp prompt, to continue navigating in the meantime:
Mélodie 1.1 90
Mélodie 4.1 91 * `jobs` # see the status of the current transfer
92 * `wait` # block until the transfer is finished
Mélodie 1.1 93
Mélodie 4.1 94 _queue_ allows to chain commands that will execute one after another:
Mélodie 1.1 95
Mélodie 4.1 96 * `queue mirror /dir1/ /dest1/`
97 * `queue mirror /dir2/ /dest2/`
98 * `queue mirror /dir3/ /dest3/`
Mélodie 2.37 99 * `wait`
Mélodie 2.29 100
Mélodie 4.1 101 Lftp executes the three _mirrors_ sequentially without intervention.
Mélodie 1.1 102
Mélodie 4.1 103 Put each queue in the background if you don't want to use "wait":
Mélodie 1.1 104
Mélodie 4.1 105 * `queue mirror /dir1/ /dest1/ &`
106 * `queue mirror /dir2/ /dest2/ &`
107 * `queue mirror /dir3/ /dest3/ &`
Mélodie 2.2 108
Mélodie 4.1 109 /!\ 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 /!\
Mélodie 1.1 110
Mélodie 4.1 111 => wait after queues is recommended in case of transfers to the same server.
Mélodie 1.1 112
Mélodie 4.1 113 ## Complete directory transfers — syntax and options
Mélodie 1.1 114
Mélodie 4.1 115 From the lftp prompt, already connected to the source server:
Mélodie 2.1 116
Mélodie 4.1 117 mirror source-directory/ /local/path/destination-directory/
Mélodie 1.1 118
Mélodie 4.1 119 or
Mélodie 1.1 120
Mélodie 4.1 121 mirror source-directory /local/path/
Mélodie 1.1 122
Mélodie 4.1 123 => The presence of the final slash `/` determines the result
Mélodie 1.1 124
Mélodie 4.1 125 Keep in mind for reading the following examples:
Mélodie 1.1 126
Mélodie 4.1 127 * With `source-directory/` the content of the directory is copied to the destination, but not the directory itself.
128 * With `source-directory` the complete directory is copied to the destination, content included.
129 * The `~/` sign for "home" should be adapted according to your case
130 * Always prefer moving into the working directory, whether it is local or remote
Mélodie 1.1 131
Mélodie 4.1 132 From the bash terminal, not connected, retrieves the complete content of the remote directory:
Mélodie 2.1 133
Mélodie 4.1 134 lftp -e "mirror <sftp://login:password@server:/source-directory/> /local-directory/destination/ ; quit"
Mélodie 1.1 135
136 ### Options
137
Mélodie 4.1 138 * `--reverse` : reverses the direction of the transfer: sends from local to remote
Mélodie 1.1 139
Mélodie 4.1 140 Ex : `mirror --reverse ~/local-directory/ remote-directory/`
Mélodie 1.1 141
Mélodie 4.1 142 * `--continue` : resumes an interrupted transfer, only re-transfers what is missing or has been modified
Mélodie 1.1 143
Mélodie 4.1 144 Ex : `mirror --continue ~/source-directory/ /local-directory/destination/`
Mélodie 1.1 145
Mélodie 4.1 146 * `--delete` : deletes at the destination files that no longer exist at the source — use with caution
Mélodie 1.1 147
Mélodie 4.1 148 Ex : `mirror --delete ~/source-directory/ /local-directory/destination/`
Mélodie 1.1 149
Mélodie 4.1 150 * `--parallel=N` : launches N transfers simultaneously — useful for directories containing many small files
Mélodie 1.1 151
Mélodie 4.1 152 Ex : `mirror --parallel=4 ~/source-directory/ /local-directory/destination/`
Mélodie 1.1 153
Mélodie 4.1 154 * `--verbose` : displays each file transferred as it goes
Mélodie 1.1 155
Mélodie 4.1 156 Ex : `mirror --verbose ~/source-directory/ /local-directory/destination/`
Mélodie 1.1 157
Mélodie 4.1 158 * `--log=file.log` : records the operations performed in a file: /!\ does not capture errors (use 2>&1 redirection for that) /!\
Mélodie 1.1 159
Mélodie 4.1 160 Ex : `mirror --log=transfert.log ~/source-directory/ /local-directory/destination/`
Mélodie 1.1 161
Mélodie 4.1 162 ## Mirroring between two remote servers
Mélodie 1.1 163
Mélodie 4.1 164 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**:
Mélodie 1.1 165
Mélodie 4.1 166 lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> ; quit"
Mélodie 1.1 167
Mélodie 4.1 168 Source and destination protocols can be different (sftp, ftp, ftps) — lftp handles the conversion transparently.
Mélodie 1.1 169
Mélodie 4.1 170 /!\ Passwords appear in plain text in the command line /!\
Mélodie 1.1 171
Mélodie 4.1 172 To avoid recording in the bash history, prefix the command with a space. This requires `HISTCONTROL` to be set to `ignorespace` or `ignoreboth`:
Mélodie 1.1 173
Mélodie 4.1 174 lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> ; quit"
Mélodie 1.1 175
Mélodie 4.1 176 => 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.
Mélodie 1.1 177
Mélodie 4.1 178 => Difference between `; quit` and `&& quit`:
Mélodie 1.1 179
Mélodie 4.1 180 * `; quit` : exits in all cases at the end of the transfer
181 * `&& quit` : only exits if the mirror finished without error
Mélodie 1.1 182
Mélodie 4.1 183 => Without `--delete`, the mirror is additive: it does not erase anything at the destination.
Mélodie 1.1 184
Mélodie 4.1 185 => To capture errors in a log file, redirect stdout and stderr:
Mélodie 1.1 186
Mélodie 4.1 187 lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> && quit" > transfert.log 2>&1
Mélodie 1.1 188
Mélodie 4.1 189 ## Quit the connection
Mélodie 1.1 190
Mélodie 4.1 191 lftp login@server:/directory> bye
Mélodie 1.1 192
Mélodie 4.1 193 or `quit` or `exit`
Mélodie 1.1 194
Mélodie 4.1 195 ---
Mélodie 1.1 196
Mélodie 4.1 197 /!\ **Detail**: The man page does not mention _bye_, it only documents _exit_ and _quit_ implicitly via "ftp:use-quit".
Mélodie 1.1 198
Mélodie 4.1 199 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.
Mélodie 1.1 200
Mélodie 4.1 201 Furthermore _exit kill_ forces all jobs to stop before quitting.
Mélodie 1.1 202
Mélodie 4.1 203 **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.
Mélodie 1.1 204

Langues / Languages

🇫🇷 Français | 🇬🇧 English