橋本ありな 橋本有菜 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新年快樂 🌞㊗☃ 最近 …