LinuxCommandLibrary

lftp

Transfer files using FTP, SFTP, HTTP, etc

TLDR

Connect to an FTP server

$ lftp [[-u|--user]] [username] [ftp.example.com]
copy

Download multiple files (glob expression)
$ mget [path/to/*.png]
copy

Upload multiple files (glob expression)
$ mput [path/to/*.zip]
copy

Delete multiple files on the remote server
$ mrm [path/to/*.txt]
copy

Rename a file on the remote server
$ mv [original_filename] [new_filename]
copy

Download or update an entire directory
$ mirror [path/to/remote_dir] [path/to/local_output_dir]
copy

Upload or update an entire directory
$ mirror [[-R|--reverse]] [path/to/local_dir] [path/to/remote_output_dir]
copy

SYNOPSIS

lftp [options] [site]
lftp site -e command
lftp -f scriptfile [site]
lftp -c command

PARAMETERS

-d, --debug
    Enables detailed debug output, useful for troubleshooting connection or transfer issues.

-e command, --command=command
    Executes the specified command after connecting to the site, then exits immediately.

-f file, --file=file
    Reads and executes commands from the specified file, then exits. Ideal for scripting complex operations.

-c command, --cmd=command
    Executes the specified command after connecting to the site, but unlike -e, it remains in interactive mode afterwards.

-p port, --port=port
    Specifies the remote port to connect to instead of the default for the given protocol.

-u user[,pass], --user=user[,pass]
    Specifies the username for authentication and an optional password.

--version
    Prints the version information of lftp and exits.

-O file, --config-file=file
    Uses the specified file as the primary configuration file instead of the default (`~/.lftp/rc`).

DESCRIPTION

lftp is a powerful and versatile command-line file transfer program, designed for advanced users and system administrators. Unlike simpler clients, lftp offers a rich set of features that make complex file operations efficient and reliable. It supports a wide array of protocols including FTP, FTPS (FTP over SSL/TLS), HTTP, HTTPS, SFTP (SSH File Transfer Protocol), FISH, and even experimental BitTorrent client functionality.
Key capabilities include robust resume support for interrupted transfers, ensuring data integrity even over unreliable connections. lftp excels at mirroring entire directory trees, allowing users to synchronize local and remote directories with ease, making it ideal for website deployments or backups. It provides a sophisticated shell-like interface with features such as job control, background transfers, bandwidth throttling, and a powerful scripting language. Users can queue multiple commands, execute them in parallel, and benefit from FXP (File eXchange Protocol) for direct server-to-server transfers. Its flexibility and comprehensive feature set make lftp an indispensable tool for managing files across various network protocols.

CAVEATS

Security Considerations: Avoid embedding passwords directly on the command line or in scripts for security reasons. Consider using lftp's `~/.lftp/rc` or `~/.netrc` files for storing credentials more securely, or rely on interactive password prompts.
Complexity: While powerful, lftp has a steeper learning curve than simpler FTP clients due to its extensive feature set and shell-like interface.
BitTorrent Support: The integrated BitTorrent client is experimental and may not offer the full feature set or performance of dedicated BitTorrent clients.

THE MIRROR COMMAND

lftp's `mirror` command is exceptionally powerful for synchronizing entire directory trees. It can upload (`mirror -R`), download, delete extraneous files, and resume broken transfers, making it ideal for website updates or backups. It's often used for one-way synchronization.

CONFIGURATION FILES

lftp uses `~/.lftp/rc` for global settings, aliases, and startup commands. It also uses `~/.lftp/bookmarks` for saving frequently used sites. These files allow extensive customization of the client's behavior and simplify routine tasks, enabling a highly personalized and efficient workflow.

HISTORY

lftp was developed by Alexander Lukyanov and first released around 1999. It was conceived as a powerful and feature-rich alternative to the traditional `ftp` client, addressing many of its limitations regarding reliability, scripting, and advanced transfer capabilities. Over the years, it has continuously evolved, adding support for new protocols like SFTP, HTTP/S, and FISH, along with sophisticated features such as mirroring, job queuing, and parallel transfers, making it a staple tool for system administrators and power users.

SEE ALSO

ftp(1), sftp(1), wget(1), curl(1), rsync(1)

Copied to clipboard