【linux命令】lftp scp rsync wget

浪尽此生 提交于 2020-02-29 16:42:25

【lftp】

lftp是Linux下的一个ftp客户端,用于登陆远程的FTP服务器。使用它的mirror命令可以把本地的文件通过lftp备份到远程FTP服务器上。

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

1、lftp登陆,随后就和其它命令行的ftp工具一样使用ftp内部命令进行控制

lftp -p 21 -u admin,123456 ftp.aaa.com
#表示使用用户名admin、密码123456登陆ftp.aaa.com这个站点,端口为21。

2、lftp的mirror命令,lftp登陆成功后,使用mirror命令用来备份文件。

将远程服务器上的文件备份到本地:
mirror [选项] [远程目录] [本地目录]

将本地文件备份到远程服务器上:
mirror -R [其它选项] [本地目录] [远程目录]

常用选项:
-c, --continue :如果镜像过程中连接中断,重新开始。
-e, --delete :删除不在远程服务器上的本地文件。
-n, --only-newer :下载远程服务器上的新文件,不能和-c一起用。
-R, --reverse :将本地文件镜像传输到远程服务器上。

-v, --verbose[=level] :设置监视级别,范围0-3,0表示不输出,3表示输出全部。

mirror [OPTS] [source [target]]
Mirror specified source directory to local target directory. If  target
directory ends with a slash, the source base name is appended to target 
directory name. Source and/or target can be URLs pointing  to  directo-
ries.

    -c, --continue      continue a mirror job if possible
    -e, --delete        delete files not present at remote site
        --delete-first       delete old files before transferring new ones
    -s, --allow-suid         set suid/sgid bits according to remote site
    --allow-chown        try to set owner and group on files
    --ignore-time        ignore time when deciding whether to download
    --ignore-size        ignore size when deciding whether to download
    --only-missing       download only missing files
    -n, --only-newer         download only newer files (-c won’t work)
    -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       reverse mirror (put files)
    -L, --dereference        download symbolic links as files
    -N, --newer-than=SPEC    download only files newer than specified time
    -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 execute them
        --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

使用lftp的-e选项,例如:
lftp -e "mirror -R --delete --only-newer --verbose /home/aaa.com /public_html/web/aaa.com" -p 21 -u admin,123456 ftp.aaa.com
登陆后自动执行-e选项中的命令。

3、lftp多线程下载

pget -n :设置使用线程数。
-c :断点续传。

lftp -c "pget -n 10 http://sourceforge.net/projects/kvm/files/qemu-kvm/1.2.0/qemu-kvm-1.2.0.tar.gz"

5、lftp使用问题
1)使用lftp的mirror命令备份时报550错
rm: Access failed: 550 dirname: Directory not empty

在lftp命令开头添加:
set ftp:list-options -a
是因为该文件夹下有隐藏文件,服务器默认不显示,所以删不掉。

2)设置lftp超时时间和重试次数
在lftp命令开头添加:
set net:timeout 10;set net:max-retries 2;set net:reconnect-interval-base 5;set net:reconnect-interval-multiplier 1;

综合这两点最终的命令为:
lftp -e "set net:timeout 10;set net:max-retries 2;set net:reconnect-interval-base 5;set net:reconnect-interval-multiplier 1;set ftp:list-options -a;mirror -R --delete --only-newer --verbose /home/aaa.com /public_html/web/aaa.com" -p 21 -u admin,123456 ftp.aaa.com

【wget】

 

wget下载FTP目录

2010年11月05日 ⁄ linuxVPS ⁄ 暂无评论 ⁄ 被围观 541 views+

wget -nH --cut-dirs=* -m --ftp-user=* --ftp-password=* ftp://*.*.*.*/*

-nH:不创建以主机名命名的目录。
--cut-dirs:忽略主机上的目录层数。
-m:下载所有子目录并且保留目录结构。
--ftp-user:FTP用户名
--ftp-password:FTP密码
ftp://*.*.*.*/*:FTP主机地址。最后可以跟目录名来下载指定目录。

* 启动
-V, –version 显示wget的版本后退出
-h, –help 打印语法帮助
-b, –background 启动后转入后台执行
-e, –execute=COMMAND 执行`.wgetrc’格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc
* 记录和输入文件
-o, –output-file=FILE 把记录写到FILE文件中
-a, –append-output=FILE 把记录追加到FILE文件中
-d, –debug 打印调试输出
-q, –quiet 安静模式(没有输出)
-v, –verbose 冗长模式(这是缺省设置)
-nv, –non-verbose 关掉冗长模式,但不是安静模式
-i, –input-file=FILE 下载在FILE文件中出现的URLs
-F, –force-html 把输入文件当作HTML格式文件对待
-B, –base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀
–sslcertfile=FILE 可选客户端证书
–sslcertkey=KEYFILE 可选客户端证书的KEYFILE
–egd-file=FILE 指定EGD socket的文件名
* 下载
–bind-address=ADDRESS 指定本地使用地址(主机名或IP,当本地有多个IP或名字时使用)
-t, –tries=NUMBER 设定最大尝试链接次数(0 表示无限制).
-O –output-document=FILE 把文档写到FILE文件中
-nc, –no-clobber 不要覆盖存在的文件或使用.#前缀
-c, –continue 接着下载没下载完的文件
–progress=TYPE 设定进程条标记
-N, –timestamping 不要重新下载文件除非比本地文件新
-S, –server-response 打印服务器的回应
–spider 不下载任何东西
-T, –timeout=SECONDS 设定响应超时的秒数
-w, –wait=SECONDS 两次尝试之间间隔SECONDS秒
–waitretry=SECONDS 在重新链接之间等待1…SECONDS秒
–random-wait 在下载之间等待0…2*WAIT秒
-Y, –proxy=on/off 打开或关闭代理
-Q, –quota=NUMBER 设置下载的容量限制
–limit-rate=RATE 限定下载输率
* 目录
-nd –no-directories 不创建目录
-x, –force-directories 强制创建目录
-nH, –no-host-directories 不创建主机目录
-P, –directory-prefix=PREFIX 将文件保存到目录 PREFIX/…
–cut-dirs=NUMBER 忽略 NUMBER层远程目录
* HTTP 选项
–http-user=USER 设定HTTP用户名为 USER.
–http-passwd=PASS 设定http密码为 PASS.
-C, –cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许).
-E, –html-extension 将所有text/html文档以.html扩展名保存
–ignore-length 忽略 `Content-Length’头域
–header=STRING 在headers中插入字符串 STRING
–proxy-user=USER 设定代理的用户名为 USER
–proxy-passwd=PASS 设定代理的密码为 PASS
–referer=URL 在HTTP请求中包含 `Referer: URL’头
-s, –save-headers 保存HTTP头到文件
-U, –user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION.
–no-http-keep-alive 关闭 HTTP活动链接 (永远链接).
–cookies=off 不使用 cookies.
–load-cookies=FILE 在开始会话前从文件 FILE中加载cookie
–save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中
* FTP 选项
-nr, –dont-remove-listing 不移走 `.listing’文件
-g, –glob=on/off 打开或关闭文件名的 globbing机制
–passive-ftp 使用被动传输模式 (缺省值).
–active-ftp 使用主动传输模式
–retr-symlinks 在递归的时候,将链接指向文件(而不是目录)
* 递归下载
-r, –recursive 递归下载--慎用!
-l, –level=NUMBER 最大递归深度 (inf 或 0 代表无穷).
–delete-after 在现在完毕后局部删除文件
-k, –convert-links 转换非相对链接为相对链接
-K, –backup-converted 在转换文件X之前,将之备份为 X.orig
-m, –mirror 等价于 -r -N -l inf -nr.
-p, –page-requisites 下载显示HTML文件的所有图片
* 递归下载中的包含和不包含(accept/reject)
-A, –accept=LIST 分号分隔的被接受扩展名的列表
-R, –reject=LIST 分号分隔的不被接受的扩展名的列表
-D, –domains=LIST 分号分隔的被接受域的列表
–exclude-domains=LIST 分号分隔的不被接受的域的列表
–follow-ftp 跟踪HTML文档中的FTP链接
–follow-tags=LIST 分号分隔的被跟踪的HTML标签的列表
-G, –ignore-tags=LIST 分号分隔的被忽略的HTML标签的列表
-H, –span-hosts 当递归时转到外部主机
-L, –relative 仅仅跟踪相对链接
-I, –include-directories=LIST 允许目录的列表
-X, –exclude-directories=LIST 不被包含目录的列表
-np, –no-parent 不要追溯到父目录
wget -S –spider url 不下载只显示过程

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!