How to Install LFTP to Download and Upload Files in Linux

When it comes to the availability of ftp (file transfer protocol) client solutions, the Linux operating system, and its numerous distributions never disappoint.

In this area, there is plenty of fish in the ocean. The Linux-based ftp clients are a mixture of GUI and non-GUI solutions. Ftp client solutions not only give you access to remote machines and servers but also enable you to easily upload/download files to/from your remote machines/servers.

[ You might also like: How to Download and Upload Remote Directory in sFTP ]

For these file transfers (uploads and downloads) to take place successfully, an FTP client has to support various data transfer protocols. The feature-rich nature of LFTP enables it to support numerous network management, network communication, and network security protocols such as FTP, sFTP, FTPS, FISH, HFTP, SSH, HTTP, HTTPS, and BitTorrent.

Another important LFTP-supported protocol is FXP (File eXchange Protocol). Through it, two remote FTP servers can comfortably exchange directory files.

Prime LFTP Features

With LFTP, you can schedule when to initiate/execute a file transfer operation. This approach is seamlessly implemented through automated scripts for users seeking an alternative from the LFTP interactive mode where file transfer operations are handled manually.

Other notable LFPT features include:

  • Transfer queues
  • Resuming partial downloads
  • Segmented file transfer
  • Bandwidth throttling
  • File directories recursive copying
  • Bookmarks support

How to Install LFTP in Linux

To use the LFTP client on the Linux operating system distribution of your choice, go with one of the following LFTP installation commands.

$ sudo apt-get install lftp     [On Debian, Ubuntu and Mint]
$ sudo yum install lftp         [On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux]
$ sudo emerge -a net-ftp/lftp   [On Gentoo Linux]
$ sudo pacman -S lftp           [On Arch Linux]
$ sudo zypper install lftp      [On OpenSUSE]    

LFTP Passwordless Access in Linux

Since LFTP supports SSH protocol, we could generate an SSH key so that we do not have to connect to our server via password authentication.

$ sudo ssh-keygen -t rsa 

Skip Enter passphrase: step by pressing [Enter] on the keyboard.

Generate SSH Key
Generate SSH Key

Next, copy generated SSH key to remote Linux server.

$ sudo ssh-copy-id ubuntu@18.118.208.XX
Copy SSH Key to Remote Linux
Copy SSH Key to Remote Linux

Test SSH passwordless access.

$ sudo ssh ubuntu@18.118.208.XX
Test SSH Passwordless Access
Test SSH Passwordless Access

LFTP Usage and Examples in Linux

To use the LFTP client, you need to adhere to its standard syntax rule. You need to be familiar with the username and hostname/IP address of the remote machine you wish to connect to via LFTP. You might optionally need to specify the port number through which LFTP will connect to the remote machine/server.

$ lftp sftp://your_username@your_hostname/host_IP_address
OR
$ lftp sftp://your_username@your_hostname/host_IP_adress:port_number

An example connection to a remote server via lftp can be implemented in the following manner:

$ sudo lftp sftp://ubuntu@18.118.208.79 

Since we configured an SSH key, just press [Enter] on your keyboard when prompted for a password.

Connect to lftp Server
Connect to lftp Server

We can use the ls command to view the directories and files on the remote server.

$ ls
View lftp Server Files
View lftp Server Files

Upload Files via LFTP

The command syntax for uploading data files under LFTP is as follows:

put name_of_file_to_send

Its example implementation will look as follows:

You first need to identify the file you need to send from the pwd (parent working directory) of your local machine.

> lpwd
> put print.pdf
Upload Files Using LFTP
Upload Files Using LFTP

Download Files via LFTP

The command syntax for downloading data files to your local machine under LFTP is as follows:

$ pget name_of_file_to_download

Its example implementation will look as follows:

> pget linuxshelltips_v2.txt
Download Files Using LFTP
Download Files Using LFTP

Now that you have managed to successfully install and use LFTP for file upload and download, its man page offers a more dynamic approach to using this awesome ftp client.

$ man lftp

Got something to say? Join the discussion.