Basic Tutorial: Installing and Using lftp
Introduction
lftp
is a powerful command-line file transfer program supporting FTP, FTPS, HTTP, HTTPS, HFTP, FISH, and SFTP. It offers advanced features like mirroring, scripting, and queueing.
Installation
On Debian/Ubuntu:
sudo apt update && sudo apt install lftp
Basic Usage
1. Connect to an FTP/SFTP Server
lftp ftp://username@ftp.example.com
Please note that you do not have to specify ftp:// unless you are wanting to connect with sftp, then do:
lftp sftp://username@ftp.example.com
Once connected, enter your password if prompted.
2. List Files
ls
3. Change Directory
cd directory_name
4. Upload a File
put localfile.txt
5. Download a File
get remotefile.txt
6. Download a Directory (Recursively)
mirror -c remote_directory local_directory
7. Upload a Directory (Recursively)
mirror -R local_directory remote_directory
8. Download Files in the Background
You can start a download in the background using &
:
get remotefile.txt &
This allows you to continue using lftp
while the file downloads.
9. Using the Queue for Background Transfers
Instead of downloading immediately, you can queue files for later:
queue get remotefile1.zip
queue get remotefile2.zip
To start all queued downloads:
queue start
10. Exit lftp
exit
lftp also supports many basic bash commands such as mkdir
, rm
, or mv
.
Advanced Features
Background Transfers with nohup
If you want to keep downloads running after logging out, use:
nohup lftp -c "open ftp://username@ftp.example.com; get largefile.zip" &
Using Bookmarks
To bookmark a site:
bookmark add mysite ftp://user@ftp.example.com
To connect using the bookmark:
open mysite
Automating with Scripts
Create a script file, e.g., script.lftp
:
open ftp://username:password@ftp.example.com
mirror -c /remote/path /local/path
exit
Run it with:
lftp -f script.lftp