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

Show last authors
1 # lftp manual
2
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.
4
5 It comes with a configuration file /etc/lftp.conf that can be used as a base for customization. It contains many commented examples.
6
7 The personal configuration file must be created under `$HOME/.config/lftp/`. Here is an example of a customized lftp.conf file:
8
9 ```
10 # For more options check the comments in the /etc/lftp.conf file
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
18 Official documentation can be found at <https://lftp.yar.ru/>
19
20 # Basic Commands
21
22 ## FTP
23
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
27
28 The password is requested interactively after connection.
29
30 ## SFTP
31
32 Same as above, but with `lftp sftp://…`
33
34 ## Navigation and information commands
35
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
43
44 ## File transfers
45
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
51
52 ## Complete directory transfers
53
54 Connected to the server:
55
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
59
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
63
64 ### Parallel transfers
65
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.
67
68 Connected to the server:
69
70 lftp login@server:/directory> mirror --parallel=4 <remote-folder/> <local-folder/>
71
72 => the prompt is blocked until the end of the transfer.
73
74 In interactive lftp, launch a mirror in the background:
75
76 lftp login@server:/directory> mirror --parallel=4 <remote-folder/> <local-folder/> &
77
78 => with the '&' sign the prompt returns immediately, the transfer continues in the background. You can continue typing commands as needed.
79
80 ## Miscellaneous
81
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
86
87 ### Miscellaneous — practical use
88
89 _jobs_, _wait_ and _queue_ are useful when launching a background transfer from the lftp prompt, to continue navigating in the meantime:
90
91 * `jobs` # see the status of the current transfer
92 * `wait` # block until the transfer is finished
93
94 _queue_ allows to chain commands that will execute one after another:
95
96 * `queue mirror /dir1/ /dest1/`
97 * `queue mirror /dir2/ /dest2/`
98 * `queue mirror /dir3/ /dest3/`
99 * `wait`
100
101 Lftp executes the three _mirrors_ sequentially without intervention.
102
103 Put each queue in the background if you don't want to use "wait":
104
105 * `queue mirror /dir1/ /dest1/ &`
106 * `queue mirror /dir2/ /dest2/ &`
107 * `queue mirror /dir3/ /dest3/ &`
108
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 /!\
110
111 => wait after queues is recommended in case of transfers to the same server.
112
113 ## Complete directory transfers — syntax and options
114
115 From the lftp prompt, already connected to the source server:
116
117 mirror source-directory/ /local/path/destination-directory/
118
119 or
120
121 mirror source-directory /local/path/
122
123 => The presence of the final slash `/` determines the result
124
125 Keep in mind for reading the following examples:
126
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
131
132 From the bash terminal, not connected, retrieves the complete content of the remote directory:
133
134 lftp -e "mirror <sftp://login:password@server:/source-directory/> /local-directory/destination/ ; quit"
135
136 ### Options
137
138 * `--reverse` : reverses the direction of the transfer: sends from local to remote
139
140 Ex : `mirror --reverse ~/local-directory/ remote-directory/`
141
142 * `--continue` : resumes an interrupted transfer, only re-transfers what is missing or has been modified
143
144 Ex : `mirror --continue ~/source-directory/ /local-directory/destination/`
145
146 * `--delete` : deletes at the destination files that no longer exist at the source — use with caution
147
148 Ex : `mirror --delete ~/source-directory/ /local-directory/destination/`
149
150 * `--parallel=N` : launches N transfers simultaneously — useful for directories containing many small files
151
152 Ex : `mirror --parallel=4 ~/source-directory/ /local-directory/destination/`
153
154 * `--verbose` : displays each file transferred as it goes
155
156 Ex : `mirror --verbose ~/source-directory/ /local-directory/destination/`
157
158 * `--log=file.log` : records the operations performed in a file: /!\ does not capture errors (use 2>&1 redirection for that) /!\
159
160 Ex : `mirror --log=transfert.log ~/source-directory/ /local-directory/destination/`
161
162 ## Mirroring between two remote servers
163
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**:
165
166 lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> ; quit"
167
168 Source and destination protocols can be different (sftp, ftp, ftps) — lftp handles the conversion transparently.
169
170 /!\ Passwords appear in plain text in the command line /!\
171
172 To avoid recording in the bash history, prefix the command with a space. This requires `HISTCONTROL` to be set to `ignorespace` or `ignoreboth`:
173
174 lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> ; quit"
175
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.
177
178 => Difference between `; quit` and `&& quit`:
179
180 * `; quit` : exits in all cases at the end of the transfer
181 * `&& quit` : only exits if the mirror finished without error
182
183 => Without `--delete`, the mirror is additive: it does not erase anything at the destination.
184
185 => To capture errors in a log file, redirect stdout and stderr:
186
187 lftp -e "mirror --continue --verbose <sftp://login:password@server1/source-directory/> <ftp://login:password@server2/destination-directory/> && quit" > transfert.log 2>&1
188
189 ## Quit the connection
190
191 lftp login@server:/directory> bye
192
193 or `quit` or `exit`
194
195 ---
196
197 /!\ **Detail**: The man page does not mention _bye_, it only documents _exit_ and _quit_ implicitly via "ftp:use-quit".
198
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.
200
201 Furthermore _exit kill_ forces all jobs to stop before quitting.
202
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.

Langues / Languages

🇫🇷 Français | 🇬🇧 English