本文主要是介绍lftp学习笔记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 0. ftp vs. lftp
- 1. 安装
- 2. 常用命令
- 2.1 登录
- 2.2 文件管理
- 2.3 文件传输
- 3. 脚本编程
- 4. 实践中的问题排查
- 参考
0. ftp vs. lftp
lftp
是一款文件传输工具,支持FTP、HTTP、SFTP、FISH等多种协议。
功能 | ftp | lftp |
---|---|---|
数据传输 | 文件 | 文件、文件夹 |
多线程传输 | 支持 | |
断点续传 | 支持 | |
脚本编程 | 支持 | |
后台执行任务 | 支持 |
1. 安装
# 方法1. conda
conda install lftp# 方法2. centos root
yum install lftp
2. 常用命令
2.1 登录
lftp ftp://[user:password@]site[:port]lftp -u user,password ftp.example.com
2.2 文件管理
命令 | 功能 |
---|---|
pwd / lpwd | 显示远端/本地所在目录 |
ls / !ls | 显示远端/本地文件列表 |
cd / lcd | 切换远端/本地目录 |
mv | 移动远端文件 |
rm | 删除远端文件 |
mrm | 删除多个远端文件,支持通配符 |
mkdir | 建立远端目录 |
rmdir | 删除远端目录 |
du | 计算远端目录大小 |
exit | 退出ftp |
2.3 文件传输
命令 | 功能 |
---|---|
get | 下载远端文件 |
mget | 下载远端文件,支持通配符 * |
pget | 下载远端文件,支持多线程 |
reget | 断点续传 |
mirror | 同步目录 |
put | 上传文件 |
mput | 上传文件,支持通配符* |
reput | 断点续传 |
数据下载示例
get remote-file [local-file] #如省略本地文件名,则默认使用远程文件的文件名
mget -c *.db # 把所有的db文件以允许断点续传的方式下载
pget -c -n 10 10G.file 以最多10个线程以允许断点续传的方式下载10G.file
mirror aaa/ # 将aaa目录整个的下载下来,子目录也会自动复制
数据上传示例
put local-file [remote-file] #如省略远程文件名,则默认使用本地文件的文件名
put linux265.tar
mirror -R 本地目录名 #将本地目录以迭代(包括子目录)的方式反向上传到ftp站点
3. 脚本编程
lftp -u username,password ftp.example.com -p 21
lftp -u username,password ftp.example.com -c "ls"
lftp -u username,password ftp.example.com -e "cd /path/to/a; put file.txt; quit"
lftp -u username,password ftp.example.com -e "mirror /remote/dir /local/dir; quit"
#!/bin/bash
HOST="ftp.example.com"
USER="yourusername"
PASS="yourpassword"lftp -u ${USER},${PASS} ${HOST} <<EOF
cd /path/to/destination
limit-rate 200KB/s
put /path/to/localfile
exit
EOF
4. 实践中的问题排查
lftp -u myuser,mypassword 1.2.3.4 -p 5555
ls
`ls' at 0 [FEAT negotiation...] # Q1. FEAT negotiation# A1. use sftp protocol
lftp -u myuser,mypassword sftp://1.2.3.4 -p 5555
ls
ls: Fatal error: Host key verification failed. # Q2.Host key verification# A2. added RSA to the list of known hosts
ssh -p 5555 myuser@1.2.3.4
#Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
#ctrl+C终止即可lftp -u myuser,mypassword sftp://1.2.3.4 -p 5555
ls #恢复正常
参考
lftp命令
LFTP 命令行工具常见用法大全详解
LFTP: how to fix the “Fatal error: Host key verification failed” error
这篇关于lftp学习笔记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!