LFTP命令笔记

安装

因为在OpenWrt命令行下scp传输文件很慢(只有2.5MB/s不到), 于是改用FTP下载. lftp是OpenWrt下的FTP客户端软件. 如果固件中未安装的话, 需要自己安装, 其依赖于两个ipk, 需要安装的ipk为

-rw-r--r--    1 root     root        424670 Feb 11 19:02 lftp_4.8.4-3_mipsel_24kc.ipk
-rw-r--r--    1 root     root         47636 Feb 11 19:05 libexpat_2.2.7-1_mipsel_24kc.ipk
-rw-r--r--    1 root     root        107228 Feb 11 19:05 libreadline8_8.0-1_mipsel_24kc.ipk

先安装libexpat和libreadline8, 再安装lftp.

root@Timecloud2:~# opkg install libexpat_2.2.7-1_mipsel_24kc.ipk 
Installing libexpat (2.2.7-1) to root...
Configuring libexpat.
root@Timecloud2:~# opkg install libreadline8_8.0-1_mipsel_24kc.ipk 
Installing libreadline8 (8.0-1) to root...
Configuring libreadline8.
root@Timecloud2:~# opkg install lftp_4.8.4-3_mipsel_24kc.ipk 
Installing lftp (4.8.4-3) to root...
Configuring lftp.

使用

登录

# lftp 用户名:密码@ftp地址:端口
lftp username:password@127.0.0.1:21
lftp username@127.0.0.1
lftp 127.0.0.1
lftp Enter --> open 127.0.0.1 --> login  

中文乱码

登录后看到的都是中文乱码(因为一般本地都是utf-8的编码), 用 set 命令解决

set ftp:charset gbk (or gb2312, utf-8)   # 设置ftp端的编码格式
set file:charset utf-8 (or gbk, gb2312)   # 设置本地编码格式

set命令的技巧

(1)输入set 查看已经设置好的命令
(2)set -a 查看所有可以设置的命令清晰网

浏览, 查找远端文件

ls *.txt                  # 查找当前目录下的所有txt文件
ls ./123/                 # 列出123目录下所有文件
find . -name "*.txt"      # 递归查找站点上所有的txt文件
find ./xx -name "*.txt"   # 查找xx目录下所有的txt文件

注意: ls第二次读取的是本地缓存, 可以用 rels 代替 ls 或者 cache off / cache on 来开关缓存, cache flush清空本地缓存

浏览本地文件, 改变本地目录

!ls /usr/local/bin/
lcd /home/123/web      # 设置本地存放目录 默认为用户home目录

下载文件

get 123.txt               # 下载123.txt文件到 /home/123/web 中
get -c 123.txt            # 断点续传下载
mget *.txt                # 批量下载所有txt文件
mget -c *.txt             # 断点续传
mget -c ./123/aaa/*.txt   # 断点续传、批量下载ftp端aaa目录下的所有txt文件

pget -c -n 10 file.dat
    # 以最多10个线程以允许断点续传的方式下载file.dat
    # 可以通过设置 set pget:default-n 5 的值而使用默认值。

mirror aaa/               # 下载aaa整个目录

上传文件

put 123.txt
mput *.txt
mirror -R aaa/          # 同下载

设置被动/非被动模式

set ftp:passive-mode 1      # 1 被动, 0非主动

多任务处理

Ctrl+z            # 将当前进行的任务移交后台处理
wait              # 将后台处理任务调至前台查看
jobs              # 查看后台进行的任务列表
kill all / job_no # 删除所有任务 或 指定的任务

# 将任务加入任务列表
queue get 123.txt
queue put 234.txt
queue mirror aaa/ 

# 任务列表
queue 
jobs              # 查看后台任务列表
queue start       # 开始任务列表
queue stop        # 停止任务列表

  

原文地址:https://www.cnblogs.com/milton/p/12296406.html