Getty Images

How to use the LFTP client to download files

The open source LFTP client supports multiple file transport types, such as FTP and HTTPS, enabling administrators to use a single interface to upload and download files.

File transfer protocols provide some of networking's oldest functionality, and they're no less important now. The HTTP and HTTPS protocols are clearly essential, and FTP services still provide benefits. Networks use many standalone file transfer utilities, such as Wget, cURL, FTP and Trivial FTP. But it would be helpful for network administrators to have a single tool that handles many protocols and offers practical features.

That's where LFTP comes in.

Here are a few of LFTP's main benefits:

  • Easy and feature-rich CLI.
  • Support for many protocols, including FTP, Secure FTP, FTP Secure, HTTP, HTTPS and more.
  • Interactive mode for features like editing, bookmarks, and file inclusions and exclusions.
  • Scriptable with noninteractive commands, which is useful for infrastructure-as-code and continuous integration/continuous delivery workflows.
  • Free and open source software.

Using LFTP enables network administrators to create a more streamlined, user-friendly and automated series of file transfer tasks without configuring and managing several tools. It might replace FileZilla, cURL, Wget and basic FTP clients for day-to-day file transfer needs.

Install LFTP

Start by installing LFTP on your Linux workstation. The process is straightforward and typical of Linux apps -- use the package manager.

Ubuntu

For Ubuntu or other Debian-based distributions, type the following commands:

$ sudo apt-get update
$ sudo apt-get install lftp

Red Hat and Fedora

For Red Hat, Fedora or similar distros, type the following:

$ sudo dnf install lftp

MacOS

The LFTP client is made for Linux, so adding it to macOS and Windows might be a little more time-consuming.

The best way to add LFTP to a Mac is to use the Homebrew package manager. Once you've installed Homebrew, type the following:

$ brew install lftp

Get details on the Homebrew installation here.

Windows

Windows users need a more significant workaround. First, install Cygwin, which is a collection of tools for Windows, similar to those found on most Linux distributions. Once you've installed Cygwin, add the Cygwin version of LFTP and its dependencies.

Another alternative is to run a Linux VM on the Windows host.

The remainder of this article assumes LFTP on a Linux system.

Establish a remote connection

Establishing a basic connection to a remote server uses syntax similar to tools like FTP or Secure Shell. You need the hostname or IP address of the remote system to which you want to connect. Then, type the following command:

$ lftp ftp://192.0.2.127

Enter a recognized username and password on the remote server. Specify the remote server type with the ftp:// attribute. Recall that LFTP supports many transfer protocols and includes the appropriate protocol in the command. In the above example, the IP address 192.0.2.127 identifies the remote system.

At this point, you're connected in interactive mode but not authenticated. The prompt changes to indicate the LFTP connection to the remote system. Enter the login or user lftp command with a recognized name and password:

$ lftp ftp://192.0.2.127:~> login yourname yourpassword

One way to simplify the connection is to include the username and password in the connection command:

$ lftp ftp://username:[email protected]

Use LFTP

Most users look for basic upload and download capabilities. LFTP includes many commands for flexibility and automation, but copying up and down is the fundamental use.

The command to copy a file from the remote server to a workstation is get. Suppose you want to download a file named server-configs.txt to your system and rename it in the process to servers.txt. Type the following:

$ lftp ftp://192.0.2.127:~> get server-configs.txt -o servers.txt

Once you finish working with the file, perhaps you need to upload a new version to the remote server. Use the put subcommand. You can also rename it back to the original file name and overwrite the existing file:

$ lftp ftp://192.0.2.127:~> put servers.txt -o server-configs.txt

Use the mirror command to download or upload directories. Many variations and ways are available to make such copies more efficient.

Another interesting LFTP feature is file editing. The edit command caches a local copy of the file on a system and opens it in the default editor, which is likely Vim or Nano. Once you complete the changes, the local copy is put back up on the remote server automatically. The edit command streamlines the process more than breaking it out into the individual get, open file editor and put steps.

Probably the most helpful command for LFTP is, well, help. Type help from the LFTP interactive mode to display a page explaining the many LFTP subcommands and configurations.

Other commands are probably familiar if you've worked with Bash or FTP, such as the following:

  • ls. Display the contents of the remote directory.
  • lcd. Change the local directory.
  • bye. Exit the LFTP shell.

Another alternative is integrating LFTP into GitHub Actions. GitHub Actions enables you to automate workflows. Some of those might include file transfers for which you wish to use LFTP. Create a workflow that includes the LFTP commands you want to run.

Bookmark remote systems

Many LFTP features contribute toward its goal of being user-friendly, but bookmarks are my favorite. You can create your own bookmarks for frequent remote connections, simplifying the process and making automation easier. These steps assume you're in the LFTP interactive interface.

Use the bookmark add command with the bookmark name you want for the current remote server (server01) to create a bookmark. This example sets ftp://192.0.2.127 as a bookmark named server01:

$ lftp ftp://192.0.2.127:~> bookmark add server01

To use the bookmark, combine the lftp command with the name you specified. Here's an example based on the bookmark above:

$ lftp server01

Use the open server01 command if you're already in LFTP interactive mode.

Display the existing bookmarks using bookmark list.

Open the LFTP bookmarks file in the system's default text editor with the bookmark edit command. Use bookmark del server01 to remove the bookmark.

Bookmarks are a useful part of the LFTP client.

Wrap-up

Look at your current processes. Do you manage many file transfers, especially among Linux systems? Do you use various protocols during this process? If so, LFTP might be for you. You can install it easily on a Linux or macOS workstation. Spend some time learning the basics, and then focus on the following two specific areas:

  1. Simplifying the interface with features like bookmarks.
  2. Automating processes with scriptable and noninteractive capabilities.

I think you'll quickly realize the benefits of a single client to manage multiple protocols.

Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to TechTarget Editorial and CompTIA Blogs.

Dig Deeper on Network management and monitoring

Unified Communications
Mobile Computing
Data Center
ITChannel
Close