使用 lftp 下载文件是一个非常高效且强大的工具,尤其适用于需要下载大文件或需要进行FTP、SFTP、HTTP等多协议下载的场景。以下是使用 lftp 下载文件的基本命令和示例。
✅ 一、基本命令格式
lftp [options] hostname [options] [command]
其中,hostname 是FTP服务器地址,command 是要执行的命令。
✅ 二、下载文件的常用命令
1. 下载文件到当前目录(默认下载路径)
lftp ftp.example.com -e "get /remote/path/to/file /local/path/to/save"
ftp.example.com:FTP服务器地址/remote/path/to/file:远程文件路径/local/path/to/save:本地保存路径
2. 下载文件并自动下载目录内容(递归下载)
lftp ftp.example.com -e "get -R /remote/path/to/dir /local/path/to/save"
-R:递归下载目录内容
3. 下载文件并使用断点续传(支持大文件)
lftp ftp.example.com -e "get -c /remote/path/to/file /local/path/to/save"
-c:使用断点续传功能
✅ 三、常用选项
| 选项 | 说明 |
|---|---|
-e |
指定要执行的命令 |
-u |
使用用户名和密码登录(需配置 lftp 的密码) |
-i |
使用HTTP基本认证 |
-p |
设置密码(仅用于HTTP) |
-P |
设置代理服务器 |
-x |
添加额外的命令(如 ls, cd 等) |
✅ 四、示例:从FTP服务器下载文件
lftp ftp.example.com -u username,password -e "get /remote/path/to/file /local/path/to/save"
username:FTP用户名password:FTP密码
✅ 五、使用 lftp 的完整命令示例
1. 下载单个文件
lftp ftp.example.com -e "get /remote/path/to/file /local/path/to/save"
2. 下载目录及子目录
lftp ftp.example.com -e "get -R /remote/path/to/dir /local/path/to/save"
3. 下载并使用断点续传
lftp ftp.example.com -e "get -c /remote/path/to/file /local/path/to/save"
✅ 六、其他相关命令
lftp ls:列出远程目录内容lftp cd:切换目录lftp mget:批量下载文件(支持递归)
✅ 七、注意事项
- 确保
lftp已安装:sudo apt install lftp(Debian/Ubuntu)或sudo yum install lftp(CentOS/RHEL) - 使用
-u时,需配置lftp的密码(如使用lftp -u username,password)
如需进一步定制下载策略(如限速、断点续传、日志记录等),可以使用 lftp 的 -- 选项或 set 命令进行配置。
如需帮助,欢迎继续提问!
