【linux命令】lftp scp rsync wget

【lftp】

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

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

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

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

二、lftp的mirror命令,lftp登录成功后,使用mirror命令用来备份文件。web

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

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

经常使用选项:
-c, --continue :若是镜像过程当中链接中断,从新开始。
-e, --delete :删除不在远程服务器上的本地文件。
-n, --only-newer :下载远程服务器上的新文件,不能和-c一块儿用。
-R, --reverse :将本地文件镜像传输到远程服务器上。cookie

-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选项中的命令。app

三、lftp多线程下载dom

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

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

五、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 不下载只显示过程

相关文章
相关标签/搜索