lftp
lftp is a sophisticated, command-line-driven file transfer program designed for Unix-like operating systems, supporting multiple network protocols such as FTP, HTTP, SFTP, Fish, and BitTorrent with DHT for reliable and efficient data transfers.[1][2] Developed by Alexander V. Lukyanov, lftp was first released in 1996 as an advanced alternative to traditional FTP clients, featuring shell-like command syntax, job control similar to BASH, and integration with the readline library for enhanced user input.[3][4][5] It emphasizes reliability through automatic retries, reget functionality, and the ability to handle parallel transfers, making it particularly useful for mirroring directories and managing large-scale file operations.[6][7] As free software licensed under the GNU General Public License (GPL), lftp has evolved through numerous releases, with the latest stable version as of November 2024 being 4.9.3, issued on November 8, 2024. It has supported full IPv6 since version 2.0 in 1999 and includes optional dependencies like GnuTLS or OpenSSL for secure connections.[1][8][9] Key features include built-in bookmarks for quick site access, a powerful mirror command for synchronized backups, and scripting capabilities that allow grouping commands for complex workflows.[6][10] Widely adopted in Linux distributions and available on platforms like macOS and Windows via ports, lftp remains a preferred tool for system administrators and developers requiring robust, protocol-agnostic file management without graphical interfaces.[11][12]Description
Purpose and design
lftp is a sophisticated command-line file transfer program designed primarily for Unix-like operating systems, providing advanced capabilities for managing file transfers across networks. It serves as a versatile client supporting multiple protocols, including FTP, HTTP, and others, while offering a shell-like interface that enhances user interaction beyond basic file transfer tools.[6] The core design philosophy of lftp emphasizes reliability, particularly in unstable or error-prone network environments, through features such as automatic retries for interrupted transfers, error recovery mechanisms that repeat operations on non-fatal errors, and support for resuming downloads even when the remote server lacks REST command compatibility. Built with job control similar to the Bash shell, lftp incorporates background processing to handle multiple tasks asynchronously, allowing users to queue and manage transfers efficiently without interrupting the session. This approach addresses limitations in traditional FTP clients by enabling robust, fault-tolerant operations suitable for large-scale or intermittent connections.[6] Historically, lftp was developed as an enhancement to the standard ftp command, introducing a more intuitive shell-like syntax for executing parallel and sequential commands, which simplifies complex transfer workflows. For instance, users can group commands within parentheses for sequential execution, such as(get [file](/page/File)1; get [file](/page/File)2), or append an ampersand to run jobs in the background, like get [file](/page/File) &, facilitating greater control and automation in file management tasks.[6]
Platform support and licensing
lftp is primarily designed for and natively supported on Unix and Unix-like operating systems, including various Linux distributions such as Debian, Fedora, and Ubuntu, as well as BSD variants like FreeBSD and NetBSD.[1][7][13] Ports to Windows are facilitated through Unix compatibility environments, notably Cygwin, which provides a POSIX layer for running Unix tools, and MSYS2, a software distribution and building platform for Windows.[14][15] The software is written in C++ and licensed under the GNU General Public License (GPL) version 3 or later, a copyleft license that promotes free software by requiring derivative works to be distributed under the same terms, ensuring users' freedoms to use, study, modify, and share the program.[2][9][16] The transition to GPL v3 occurred in version 3.7.7 to accommodate dependencies like gnulib modules that mandate this version.[9] Building lftp from source requires the GNU Readline library for enhanced interactive input, including command editing and history, and the zlib library for compression features.[2][1] For support of secure protocols, optional dependencies include OpenSSL or GnuTLS development libraries to handle encryption and TLS/SSL connections.[2] lftp is distributed through native package managers on Unix-like systems, such asapt on Debian-based distributions (e.g., sudo apt install lftp on Ubuntu or Debian) and yum or dnf on Red Hat-based systems (e.g., sudo yum install lftp on CentOS or Fedora).[17][18] Users seeking the latest version or custom builds can compile it from official source tarballs released on the project's website.[1]
Development history
Origins and initial releases
lftp was created by Alexander V. Lukyanov, a software developer based in Yaroslavl, Russia, during the mid-1990s.[3] Lukyanov initiated the project to overcome the shortcomings of contemporary FTP clients, which struggled with the unreliable internet connections common in that era, often characterized by frequent dropouts and variable bandwidth.[19] From its inception, lftp's design prioritized robustness, incorporating queuing mechanisms for multiple transfers and automatic resumption capabilities to restart interrupted downloads seamlessly, even if the remote server did not support partial transfers.[19] These features addressed the practical challenges of file transfers over unstable networks, allowing users to continue operations without manual intervention after errors.[19] The first public release, version 0.1, arrived in August 1996, concentrating on foundational FTP improvements such as enhanced error handling and basic connectivity retries.[1] Early versions quickly evolved, with distributions like Debian including lftp 0.10.0 in 1997.[20] lftp was initially distributed via mailing lists and incorporated into early Linux distributions, fostering adoption within academic and open-source communities.[21] By 1998, the release of version 0.14.0 highlighted its growing popularity, as announced on platforms like Linux Weekly News, where it was praised for its shell-like interface and reliability features.[3]Evolution and maintenance
Following its initial releases, lftp underwent significant expansions in protocol support during the early 2000s. Version 2.0, released in June 1999, introduced HTTP support alongside improvements to ETA reporting and overall protocol handling.[9] In the 2.6 series, launched in late 2003, SFTP and FISH protocols were added, providing secure file transfer options over SSH and enabling lftp to serve as a versatile alternative to dedicated sftp clients.[22] The 3.0 release on April 2, 2004, brought further refinements, while BitTorrent support was integrated in version 3.7.16 in August 2009, allowing the tool to function as a basic peer-to-peer client with DHT capabilities added in later updates.[23] In the 2010s, the project's source code repository migrated to GitHub under maintainer Alexander V. Lukyanov (username lavv17), promoting easier collaboration, issue tracking, and pull requests for ongoing development.[2] The most recent stable release, version 4.9.3 on November 8, 2024, addressed several issues including SFTP out-of-order packet handling, UDP tracker looping in BitTorrent mode, core dumps, and compilation problems across environments, alongside implicit performance gains from these fixes; support for TLS 1.3 was refined in the 4.9.x series through underlying library integrations like GnuTLS and OpenSSL.[8] Maintainer activity has been constrained since 2020, evidenced by the four-year gap between 4.9.2 (August 2020) and 4.9.3, during which only minor patches were applied.[23] Community involvement remains active via the official mailing list at [email protected], where users report bugs, propose fixes, and discuss enhancements; the 4.9.x series has emphasized security patches, such as vulnerability resolutions in 4.8.4, and compatibility updates for modern systems and protocols.[24]Features
Supported protocols
lftp supports a range of network protocols for file transfers, enabling connections to remote servers via standard and secure methods. The core protocol is FTP (File Transfer Protocol), which facilitates basic anonymous and public file transfers in both active and passive modes, adhering to standards such as RFC 959, RFC 2389, RFC 3659, and extensions for deflate compression.[6] Secure variants enhance data protection during transfers. FTPS (FTP over SSL/TLS) provides encrypted FTP sessions using RFC 4217, requiring either GnuTLS or OpenSSL libraries for implementation. HTTPS (HTTP over SSL/TLS) secures web-based transfers with encryption and authentication support per RFC 2616 and RFC 2617. SFTP (SSH File Transfer Protocol) operates over SSH version 2 as a subsystem, following draft-ietf-secsh-filexfer-13, for authenticated and encrypted file operations.[6] Additional protocols extend lftp's capabilities beyond traditional client-server models. HTTP (Hypertext Transfer Protocol) allows retrieval of files from web servers using GET and POST methods, compliant with RFC 1945 and RFC 2616, with partial support for WebDAV. FISH (Files over SHell) enables file access over SSH connections to Unix-like accounts, mimicking scp-like operations without a dedicated server. BitTorrent supports peer-to-peer torrent downloads and seeding via the 'torrent' command, implementing specifications such as BEP 0003, BEP 0005 (DHT), and BEP 0006. HFTP (HTTP File Transfer Protocol) permits FTP access through an HTTP proxy when configured, such as via the ftp:proxy setting pointed to an HTTP endpoint.[6][25] lftp employs automatic protocol detection through URL schemes, such as ftp:// for FTP, ftps:// for FTPS, http:// for HTTP, https:// for HTTPS, sftp:// for SFTP, and fish:// for FISH, simplifying connection setup in commands like 'open'. Proxy support is available for HTTP and FTP protocols, configurable via environment variables or lftp settings like http:proxy and ftp:proxy.[6]Core functionalities
lftp provides advanced tools for efficient file transfers and directory management, leveraging multiple connections and automation to enhance reliability and speed across supported protocols.[25] Its core functionalities emphasize segmented downloading, where thepget command splits files into segments fetched via parallel connections, accelerating transfers by utilizing available bandwidth more effectively.[6] Resuming partial transfers is supported through commands like reget and get -c, allowing interrupted downloads or uploads to continue from the point of failure without restarting.[6] Additionally, bandwidth throttling via the net:limit-rate setting enables users to cap transfer speeds per connection, host, or globally, preventing network overload.[6]
For directory operations, lftp includes recursive mirroring with the mirror command, which synchronizes entire directory trees between local and remote locations, including options for reverse mirroring (-R) to upload changes and FXP (direct server-to-server transfers) for FTP-to-FTP operations.[6] Transfer queues facilitate batch processing by queuing multiple commands for sequential or timed execution per site, supporting operations like --delete to remove processed items.[6] The delete-after functionality, available via -E in get or --Remove-source-files in mirror, automatically removes source files post-transfer to streamline synchronization tasks.[6]
Utility features enhance usability with bookmarks, stored in ~/.lftp/bookmarks, for saving and quickly accessing frequent server sessions.[6] Paging of remote files is possible by piping output to external viewers like zmore, allowing inspection without full downloads.[25] Command history persists in a file, enabling recall and reuse of previous inputs for efficient session management.[6]
Error handling is robust, with automatic retries on failures configurable via net:max-retries, defaulting to unlimited attempts on retriable errors or timeouts to ensure completion.[6] Progress displays during transfers show rates, estimated times, and status updates, toggled by cmd:show-status for monitoring long-running operations.[6]
Usage
Interactive mode
lftp operates in interactive mode by default when invoked from the command line without the-c or -f options, providing a shell-like environment for real-time file transfer operations. To start an interactive session, users execute the command lftp [options] [site], where [options] can include settings like -u username,password for authentication or -p [port](/page/Port) for specifying a non-standard port, and [site] is the target URL such as ftp://[example.com](/page/Example.com). If no site is provided, lftp launches directly into the interactive prompt, denoted by lftp :~>, allowing subsequent connections and commands to be entered manually.[6]
Once in interactive mode, establishing a connection uses the open command, formatted as open [options] site, for example, open ftp://[user](/page/User)@host. This command supports various protocols and handles authentication through options like -u [user](/page/User)[,pass] to specify credentials, or by falling back to the ~/.netrc file for stored login details if none are provided in the URL. Proxy configurations are managed via settings such as set ftp:[proxy](/page/Proxy) http://proxyhost:[port](/page/Port), enabling connections through intermediaries for restricted networks. After a successful connection, the prompt updates to reflect the remote site, such as lftp [user](/page/User)@host:/[path](/page/Path)>.[6]
Basic navigation within the remote filesystem employs familiar commands analogous to shell utilities: ls lists directory contents (with caching for efficiency), cd rdir changes the current remote directory (e.g., cd /documents), and pwd displays the present working directory as a full URL. For file operations, get rfile [-o lfile] retrieves a remote file to the local system (optionally renaming it locally), while put lfile [-o rfile] uploads a local file to the remote server (with optional remote renaming). These commands support progress indicators and can be interrupted with Ctrl+C for resuming later if segmentation is enabled, though basic usage focuses on straightforward transfers.[6]
Session management in interactive mode includes commands to synchronize directories or exit cleanly: mirror [options] [source [target]] performs a basic recursive copy from remote to local (or vice versa with --reverse), with --verbose enabling detailed output on files processed. To end the session, bye or quit disconnects from the host and returns to the shell, preserving any queued jobs if applicable. For users new to lftp, installation is typically handled via package managers, such as apt install lftp on Debian-based systems. Advanced scripting builds on this interactive foundation but is covered separately.[6]
Scripting and batch operations
lftp supports non-interactive scripting and batch operations through command-line flags and built-in mechanisms, enabling automation of file transfers without user intervention. The-c flag allows execution of a single command string, such as lftp -c "open ftp://user:pass@host; mirror /remote/dir /local/dir", which connects to the specified site and mirrors the directory contents. Similarly, the -f flag reads and executes commands from a script file, for instance lftp -f script.lftp where the file contains lines like open ftp://host followed by transfer commands. These options facilitate unattended operations, contrasting with interactive sessions by processing predefined sequences and exiting upon completion.[6]
For automation, lftp integrates seamlessly with scheduling tools like cron for periodic tasks. A common example is a cron job configured as */5 * * * * lftp -c "open sftp://user@host; mirror -c /remote /local", which synchronizes directories every five minutes, ensuring up-to-date backups or deployments. Shell scripts can handle dynamic sites by generating a list of files and using it for selective transfers, such as remotefiles="file1 file2"; lftp -c "open host; mget $remotefiles". Environment variables enhance configurability; for example, setting LFTP_HOME=/custom/path directs lftp to use a specific directory for configuration files, allowing tailored setups for different automation scenarios without altering global defaults.[6][26][27]
Advanced batch processing leverages lftp's job queue for parallel or sequential transfers within scripts. Commands like queue get file1; queue get file2; queue start enqueue multiple downloads, executing them concurrently up to a configurable limit (default 5), which optimizes bandwidth usage in automated workflows. Error handling and logging are enabled via settings such as set log:enabled true and set log:file /path/to/log, capturing transfer details to files like ~/.lftp/transfer_log for post-run analysis and debugging in batch environments.[6]
Integration with other tools extends lftp's utility in hybrid setups; for instance, shell scripts can conditionally invoke lftp based on file checks before using rsync for local synchronization, creating robust pipelines like if [ -d /local/target ]; then lftp -c "open ftp://user@host; mirror /remote /local/ftp"; [rsync](/page/Rsync) -av /local/ftp/ /local/target/; fi. This approach combines lftp's protocol flexibility with rsync's efficiency for comprehensive data management tasks.[6][27]