How to Use LFTP for FTP and SFTP File Transfers in Linux

Introduction

Managing files on remote servers is a common task for system administrators, developers, and website owners. While traditional FTP clients provide basic file transfer capabilities, LFTP offers a powerful command-line alternative with advanced features such as parallel downloads, directory mirroring, scripting support, and secure file transfers.

In this guide, you’ll learn how to install LFTP, connect to FTP/SFTP servers, upload and download files, synchronize directories, and automate transfers through scripts.

What is LFTP?

LFTP is a sophisticated command-line file transfer program that supports multiple protocols, including:

  • FTP
  • FTPS
  • SFTP
  • HTTP
  • HTTPS
  • FISH

Unlike standard FTP clients, LFTP provides features such as resumable transfers, segmented downloads, automated synchronization, and scripting capabilities, making it ideal for both interactive use and automation.

LFTP Workflow Chart

Installing LFTP

Install LFTP on Ubuntu

On Ubuntu and Debian-based distributions, install LFTP using the APT package manager:

sudo apt-get update
sudo apt-get install lftp

Install LFTP on CentOS, Fedora, and RHEL

For CentOS, Fedora, and RHEL systems, use YUM or DNF:

sudo yum install lftp

For newer Fedora and RHEL versions:

sudo dnf install lftp

Connecting to an FTP or SFTP Server

Before connecting, ensure you have:

  • FTP/SFTP username
  • Server hostname or IP address
  • Password (if required)

Connect to your server using:

lftp ftp://username@hostname

For SFTP connections:

lftp sftp://username@hostname

You will be prompted for the password if it is not provided in the command.

Basic Navigation Commands

Once connected, you can navigate the remote server similarly to a Linux shell.

List Files and Directories

ls

Change Directory

cd directory_name

Display Current Directory

pwd

Downloading Files with PGET

LFTP’s pget command downloads files using multiple connections, which can significantly improve download speeds.

pget file_from_server.txt

This command retrieves the specified file from the remote server to your local machine.

Uploading Files with PUT

To upload a local file to the remote server:

put file_from_workspace_file.txt

The file will be transferred from your current local directory to the current remote directory.

Mirroring Directories to the Server

One of LFTP’s most powerful features is directory synchronization.

Reverse Mirror (Upload Local Directory to Server)

mirror -R

Example:

mirror -R /home/user/project /public_html/project

The -R option performs a reverse mirror, copying local files and directories to the remote server.

Download a Remote Directory

mirror /remote/directory /local/directory

This synchronizes files from the server to your local machine.

Exiting the LFTP Session

To leave the LFTP shell, run:

bye

or

exit

Automating File Transfers with Scripts

LFTP commands can be executed directly from shell scripts without entering an interactive session.

Example:

lftp -e 'mirror /home/user/ /home/user/Videos/; quit' \
-u user,password ftp://ip

This command:

  1. Connects to the FTP server.
  2. Mirrors the specified directory.
  3. Exits automatically after completion.

This approach is particularly useful for scheduled backups, deployments, and synchronization tasks.

Best Practices for Using LFTP

  • Use SFTP whenever possible for secure file transfers.
  • Automate routine uploads and backups using shell scripts.
  • Verify synchronization paths before running mirror operations.
  • Use segmented downloads with pget for large files.
  • Store credentials securely and avoid hardcoding passwords in scripts.

Conclusion

LFTP is a versatile and powerful file transfer tool that goes far beyond the capabilities of traditional FTP clients. With support for FTP, SFTP, automated mirroring, parallel downloads, and scripting, it is an excellent choice for administrators and developers who need reliable file management on remote servers.

Whether you’re transferring a single file, synchronizing an entire website, or automating server backups, LFTP provides a fast and efficient solution that can significantly streamline your workflow.

Frequently Asked Questions (FAQ)

1. What is the difference between FTP and LFTP?

FTP is a file transfer protocol, while LFTP is a command-line client that uses FTP, SFTP, FTPS, and other protocols to transfer files. LFTP includes advanced features such as mirroring, scripting, and segmented downloads.

2. Is LFTP secure?

LFTP itself supports secure protocols such as SFTP and FTPS. For encrypted file transfers, it is recommended to use SFTP instead of standard FTP.

3. Can I automate file uploads and backups with LFTP?

Yes. LFTP can be integrated into shell scripts and cron jobs, making it ideal for automating backups, deployments, and directory synchronization.

1.How to Fix the OpenSSH SFTP Server “Subsystem Not Found” Error

2.Why WordPress Requests FTP Credentials During Plugin Installation

3.Resolving WordPress FTP Credential Prompts When Installing Plugins

Talk to our experts

Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Comment

Scroll to Top