Enhanced
Enhanced
LFTP is an alternative to the FTP command set, which supports many protocols and offers countless parameters.
Although pretty much outdated, the File Transfer Protocol (FTP) still plays a significant role. For 20 years, LFTP has offered a greatly expanded command set for the command line that handles secure transmissions, without being excessively difficult to handle.
FTP dates back to 1985. Designed for transferring files between two computers, FTP is a relic from the infancy of modern IT. Today it has lost much of its former importance, not least because of some serious security problems: It neither encrypts the FTP username and password, nor protects the data against manipulation during transfer.
FTP via SSL (FTPS) or SSH (SFTP) counteracts these weaknesses. The two methods are considered to be equally secure, and they encrypt both data and metadata during transmission. In most cases, SFTP proves to be more flexible and much simpler in practice.
Alternatives
FTP alternatives have been around for a long time – on Linux, the venerable secure copy (scp
) has been used to transfer data to other machines from the command line. In the meantime, WebDAV (Web Distributed Authoring and Versioning), a kind of extension of HTTP with new commands, has also developed into a useful replacement.
Nevertheless, FTP is a marathon runner for various reasons, most often because many web hosts only offer FTP and leave WebDAV or SSH out of the equation. FTP is thus likely to be around for a while.
LFTP is a very powerful extension of the original FTP command set that has been under development since 1997. It is developed by Alexander Lukyanov, is licensed under the GNU Public License (GPL), and was last updated to version 4.8.0 in July 2017 [1]. LFTP supports a wide range of protocols, including plain vanilla FTP, along with FTPS, SFTP, HTTP, HTTPS, HFTP, FXP (see the "FXP" box), Fish, and BitTorrent.
FXP
FXP, which stands for File Exchange Protocol, is a method defined in FTP, but not named there, for controlling file transfers between two servers on a client. The files move directly from server to server, saving time. Many current FTP clients support FXP.
Special Features
LFTP stands out from most other command-line FTP clients with advanced features such as recursive mirroring and the ability to update entire directory trees and manage bookmarks. Several simultaneous sessions to different servers are implemented by assigning commands to slots in a separate shell. Additionally, scheduled transfers can be queued and scheduled, and bandwidth use can be managed. If a transmission breaks down, LFTP resumes it later on at the same location. If you exit LFTP, it continues to process the active tasks in the background.
Client-Server Model
LFTP can be found in the repositories of most distributions; thus, you can usually install it with the package manager.
To test LFTP without an active server, it is best to install an FTP server on a second local machine, to which LFTP then establishes a connection. For example, the very secure FTP daemon (vsftpd
) [2] is a good way to go, because it does not require any configuration for simple tests. Before you can start, all you have to do is remove the #
comment sign in front of the #write_enable=YES
line in /etc/vsftpd.conf
.
Last but not least, create a directory on the client computer for the test and fill it with some data.
Which LFTP?
If you want to use LFTP with FTPS, you might need to compile the package with SSL support yourself. Use the command line to check whether this is necessary by entering the
which lftp
command to determine where LFTP has been installed. After calling
ldd /<path>/<to>/lftp
check its output to see whether one of the lines starts with libssl (Figure 1); for example:
$ ldd /usr/local/bin/lftp | grep ssl
If this is not the case, and you want to use FTPS instead of SFTP, follow the instructions in the "DIY LFTP" box.
DIY LFTP
On Debian, you need to install the following dependencies:
- libgnutls30
- libgcc1
- libreadline-dev
- libssl-dev
- libtinfo5
- libunwind8
- libghc-zlib-dev
Depending on the version of the system you are using, you might need other versions of these packages. If further software is missing, entering ./configure
will usually let you know. Build LFTP as shown below with the usual three-card trick – ./configure
, make
, and make install
– and use ldd
to test your home-grown LFTP version for SSL support.
$ wget http://lftp.yar.ru/ftp/lftp-4.8.0.tar.gz$ tar xfz lftp-4.8.0.tar.gz $ cd lftp-4.8.0 $ ./configure --with-openssl=/usr/lib $ make $ sudo make install $ ldd /usr/local/bin/lftp | grep ssl libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007fbe89dbd000)
At system startup, LFTP will search the /etc/lftp.conf
, ~/.lftprc
, and ~/.lftp/rc
files (in that order) for configuration. Directives that you create in the home directory take precedence over the global configuration in the /etc
directory. The instructions always start with set
and follow the
set <Option>:<Switch>[on|off]
scheme.
Practice
For test purposes, it is best to use two local computers that serve as the server and client. LFTP will behave in the same way as if you were using remote servers, but it will be easier to locate sources of problems and errors. Unless you specify otherwise, LFTP uses the SFTP protocol. Ports other than standard port 21 are entered at the end of the connection command in the form :<port>
.
For more feedback, add the -d
(debug information) option to the lftp
call. The -h
(--help
) parameter offers little help when it comes to the application's options. An intelligible version of the LFTP man page can be found on the Lifewire website [3].
To get used to the LFTP shell, first download or upload files from the server. To do this, log on to the server with the lftp <user>@[<FQDN>|<IP>]
command; for example:
lftp ft@192.168.178.123
After the connection is established, you are in the LFTP shell.
The ls
command lists the current directory content on the server. With a preceding exclamation mark (!
), you can redirect the command to the client; !ls
shows the contents of the client's current local working directory (Figure 2). Some commands can be executed with a preceding small l
(ell, for "local") on the client, and other commands can be preceded by either switch. Usage is not completely consistent. To simplify things, you can define command aliases to suit your own requirements.
Up and Down
To upload a file from the client to the server, use the put
command, to which you add the name of the file in question (put <file>
). The -d
parameter used for logging in shows you what is happening in the background in detail. If you want to put the file in a certain directory, go there with the cd
command and then run put
.
Following the same pattern, get
lets you download a file. However, with pget
, LFTP offers an alternative that distributes the data transfer over several parallel connections, thus speeding up the download on servers with slow connections. In practice, you would first change to the directory in which you want to store the downloaded file !cd
or lcd
followed by get <file>
or pget <file>
.
Mirroring and Synchronizing
You can use the mirror
command to move a folder or an entire directory tree to a server. Use lpwd
to make sure that you are in the correct local directory. If necessary, change this with lcd
. You can do the same with pwd
and, if necessary, cd
on the server side. The command to upload the directory is simply mirror -R
, the reverse path from the server to the client works with mirror
.
Alternatively, you can specify the directories with the
mirror -R /<Server folder>/ /<Client path>/
command. After the comparison, if you change a file or the file repository in the source directory and then execute the mirror command again, LFTP simply syncs the changes with the other side. The mirror
command also supports several parallel connections, which you can initiate with mirror -P
or define more precisely with:
mirror -parallel=<n>
LFTP plays to one of its strengths in the case of large volume transmissions, in particular by displaying a progress bar and the transmission speed, which you can reduce if required. If a transmission fails once, it can be resumed with the -c
parameter, even if you terminated LFTP in the meantime.
Likewise, LFTP can handle several transmissions at the same time, and they can be sent off into the background as desired and then moved into the foreground again. To view details of the actions performed, take a look at the ~/.lftprc/
directory, where logs of all sessions that document the actions in detail reside.
When all work is complete, exit LFTP with exit
or bye
and return to the shell command line.
Advanced Functions
In addition to transferring files and directories between client and server, LFTP has many additional features and hundreds of control parameters. The most important commands are briefly summarized in Table 1.
Table 1
Command Reference
Command | Function |
---|---|
File Transfers |
|
put <File> |
Transfer file from client to server |
get <File> |
Transfer file from server to client |
Sync Entire Directories |
|
mirror -R |
Sync directory from client to server |
mirror |
Sync directory from server to client |
Bookmarks |
|
bookmark add <Name> |
Create bookmarks |
bookmark list |
List bookmarks |
open <Name> |
Open bookmarks |
Time Control and Batch Processing |
|
at <hh:mm> <Command> |
Specify time |
queue mirror <Folder> |
Create queue (directory) |
queue mirror <File> |
Create queue (just one file) |
queue start |
Start queue |
For example, you can use the at <time>
time control transmission parameter; queue
lets you create queues; and -n <number>
divides the file transmission into several parts. If you want to repeat an action later, create a bookmark with bookmark add <name>
, and bookmark list
lets you view all the bookmarks you have created.
Generally, you can initiate parallel transfers with -P
(--parallel
)=<n>
. LFTP supports FXP transfers from server to server that excludes the client. You can download web pages with HTTP – even the Torrent protocol is supported. LFTP can also be controlled with scripts.
Conclusions
The very powerful and versatile LFTP is comparatively easy to master. Many commands are the same or similar to those of the shell or the conventional FTP command set. The application is still very much active, even after 20 years of development, as can be seen by the release of the fourth update in 2017.
LFTP, on the other hand, lacks up-to-date documentation. Many of the instructions found online are no longer correct. Nevertheless, if you appreciate the command line and want to or need to use FTP, I strongly recommend LFTP as a more powerful alternative.
Infos
- LFTP: https://lftp.yar.ru
- vsftpd: https://security.appspot.com/vsftpd.html
- LFTP command reference: https://www.lifewire.com/lftp-linux-command-4093434