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