桥本ありな 桥本有菜 Arina Hashimoto
桥本ありな 桥本有菜 Arina Hashimoto

可FTP同步的LFTP软体

LFTP是一套也很强劲的FTP软体,主要比NcFTP多了可同步的功能,如果你有一台只开放FTP的主机,在没办法使用rsync的时候又想随时备份该台主机的时候,就可以利用LFTP,对我来说还是NcFTP比较常用,1行指令上传一堆档案,用到的资源大多又有rsync作备份了,所以这是看个人喜好啦 🤖🤓🤖

Step.1 安装方法

安装LFTP前只要先增加CentOS官方认可的epel这家的repo即可。

sudo yum remove -y epel-release
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --enable epel

最后下这个指令就可以完成安装了。yum install -y lftp

Step.2 基本的使用方法

lftp [-d] [-e cmd] [-p port] [-u user[,pass]] [site] lftp -f script_file
lftp -c commands

参数说明

-p // 后面可以直接接上远端 FTP 主机提供的端口
-u // 帐号与密码,如果没有加帐号密码, lftp预设会用尝试匿名登入
-f // 可以将指令写入脚本中给lftp运作
-c // 后面直接加上所需要的指令

范例:我建立一个档案lftp.txt,内容如下

open qoo.com -p 21 -u qoo_user,qoo_pw
lcd /backup/520.be/
cd /web/www/520.be/
mirror -c
exit

储存后用这个指令即可,mirror后面如果变成-cR就变成上传档案到远端,懂了方法后当然也可以写到cronjob方便备份囉。

lftp -f /root/lftp.txt

LFTP指令说明

mirror [OPTS] [source [target]]

Mirror specified source directory to local target directory. If tar-get directory ends with a slash, the source base name is appended to target directory name. Source and/or target can be URLs pointing to directories.

-c, –continue // 断点续传
-e, –delete // 比较远端和本地端的档案,如果远端没有的档案,就删除本地端的档案
–delete-first // delete old files before transferring new ones
–depth-first // descend into subdirectories before transferring files
-s, –allow-suid // 储存远端FTP档案的属性
–allow-chown // try to set owner and group on files
–ascii // use ascii mode transfers (implies –ignore-size)
–ignore-time // ignore time when deciding whether to download
–ignore-size // ignore size when deciding whether to download
–only-missing // download only missing files
–only-existing // download only files already existing at target
-n, –only-newer // 只下载比本地端新的档案(此时-c断点续传选项无效)
–no-empty-dirs // don’t create empty directories (implies –depth-first)
-r, –no-recursion // don’t go to subdirectories
–no-symlinks // don’t create symbolic links
-p, –no-perms // don’t set file permissions
–no-umask // don’t apply umask to file modes
-R, –reverse // 反向镜像(就是上传档案啦)
-L, –dereference // download symbolic links as files
-N, –newer-than=SPEC // download only files newer than specified time
–on-change=CMD // execute the command if anything has been changed
–older-than=SPEC // download only files older than specified time
–size-range=RANGE // download only files with size in specified range
-P, –parallel[=N] // download N files in parallel
–use-pget[-n=N] // use pget to transfer every single file
–loop // loop until no changes found
-i RX, –include // RX include matching files
-x RX, –exclude // RX exclude matching files
-I GP, –include-glob // GP include matching files
-X GP, –exclude-glob // GP exclude matching files
-v, –verbose[=level] // verbose operation
–log=FILE // write lftp commands being executed to FILE
–script=FILE // write lftp commands to FILE, but don’t executehem
–just-print, –dry-run // same as –script=-
–use-cache // use cached directory listings
–Remove-source-files // remove files after transfer (use with caution)
-a // same as –allow-chown –allow-suid –no-umask

使用多个线程来下载远端HTTP/FTP档案,预设为5个线程

pget [OPTS] rfile [-o lfile]

-c // 断点续传
-n // 指定使用几个线程下载
-o // 档案储存位置

范例lftp -c 'pget -c -n 10 http://voip.hinet.net/msjavx86.exe -o /web/www/520.be/msjavx86.exe'

下载多个档案
mget [-c] [-d] [-a] [-E] [-O base] files

Gets selected files with expanded wildcards.
-c // 断点续传
-d // create directories the same as file names and get the files into them instead of current directory.
-E // 下载完成后移除远端FTP的档案(谨慎使用)
-a // 使用ascii模式(预设为binary模式)
-O // 档案储存位置

上传多个档案
mput [-c] [-d] [-a] [-E] [-O base] files

Upload files with wildcard expansion. By default it uses the base name of local name as remote one. This can be changed by ‘-d’ option.

-c // 断点续传
-d // create directories the same as in file names and put the files into them instead of current directory
-E // 上传完成后移除本地端档案(谨慎使用)
-a // 使用ascii模式(预设为binary模式)
-O // 档案储存位置

其他阿沙不鲁的指令

! shell command // 执行本地端shell的命令(由于LFTP没有lls,故可用!ls来替代)
alias [name [value]] // 定义别名
bookmark [subcommand] // 设定书签
cat,more, zcat, zmore // 查看远端FTP档案
cd rdir // 切换远端FTP目录
chmod mode files // 变更远端FTP的档案或目录的权限
du // 计算远端FTP目录的大小
get [-E] [-a] [-c] [-O base] rfile [-o lfile] // 下载远端FTP档案
lcd ldir // 切换本地端目录
lpwd // 显示本地端目录
ls // 显示远端FTP档案列表(!ls显示本地档案列表)
mkdir [-p] dir(s) // 建立远端FTP目录。参数mkdir -p可连子目录一起建立
mrm // 删除多个远端FTP档案(支援万用字元)
mv file1 file2 // 移动远端FTP档案(重新命名远端档案)
put [-E] [-a] [-c] [-O base] lfile [-o rfile] // 上传档案
pwd // 显示远端FTP目前所在目录
rm [-r] [-f] files // 删除远端FTP档案。参数rm -r可删除整个目录,参数rm -f则不显示错误讯息
rmdir dir(s) // 删除远端FTP目录
exit // 退出LFTP

可使用的设定

set ftp:charset UTF-8 // 设定远端FTP用UTF-8编码,另外可设定big5为繁体中文、gbk为简体中文
set file:charset “UTF-8” // 设定本地端档案列表用UTF-8编码,另外可设定big5为繁体中文、gbk为简体中文
set net:limit-rate 10000,10000 // 限制上传下载各为10KB/s

Step.3 完整指令 or man lftp

线上说明手册:http://tutorials.papamike.ca/pub/lftp.html

列印本文 列印本文

关于 穷苦人家的小孩

In every democracy, the people get the government they deserve. ~Alexis de Tocqueville
上一篇:
下一篇:

您可能会喜欢

有坂深雪 Miyuki Arisaka

[Debain]安装HestiaCP

2021新年快乐 🌞㊗☃ 最近 …