【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 不下載只顯示過程

相關文章
相關標籤/搜索