最後更新: 2023-09-09
介紹
支援 ftp, ftps, sftp, http, https
目錄
基本用法
lftp [-d] [-e cmd] [-p port] [-u user[,pass]] [site]
lftp -c commands
lftp -f script_file
Opts
- -e commands # Execute given commands and don't exit.
-
-c commands # Execute the given commands and exit.
# (Commands can be separated with a semicolon, `&&' or `||' ) - -d # Switch on debugging mode.
Example
lftp -u datahunter 192.168.1.1
or
lftp [email protected]
Configure File
/etc/lftp.conf and then ~/.lftprc
用來放 "aliases" 及 "set" commands
set ftp:passive-mode on set ftp:list-options -a
Put / Get
-c continue, reput. It requires permission to overwrite remote files
-E delete source files after successful transfer (dangerous)
Variables
"set -a" to see all variables and their values
"set -d" to see list of defaults.
Passive-mode (PASV)
lftp :~> set ftp:passive-mode on
看見隱藏的 dot-file
lftp :~> set ftp:list-options -a
Mirror
* Upolad folder 要用到 mirror cmd ( mirror -R upload_an_folder to server )
mirror [OPTS] [source [target]]
Default action: Download From Server
"mirror -R" reverse mirror (uploads to server)
- -c, --continue // continue a mirror job if possible
- -e, --delete // 當對方沒此檔案時, 本地都就刪除它
- -n, --only-newer //download only newer files (-c won't work) => 它不會續存未完成的 File
- -P, --parallel[=N] // 同時下載幾多個檔案
- -L, --dereference //download symbolic links as files
- --loop // loop until no changes found
* 當有同名檔案時, 那會先 Delete 再 Download
使用:
mirror -R data/
MyFolder1: Getting directory contents (0) [Making data connection...] # 當結構好複雜時會得好耐
mirror -n -P 3
Exclude:
- -x, -exclude
- -X, --exclude-glob
mirror --exclude logs/
mirror --exclude-glob *~$
Log:
--log=FILE // 將所有操作 log 下
i.e.
get -e -O /root/project/daily_ftp_bak/Wed ftp://user:[email protected]/public_html/test3.bin
Finish Output:
Total: 252 directories, 2628 files, 0 symlinks New: 2628 files, 0 symlinks 41150360 bytes transferred in 265 seconds (151.7K/s)
i.e.
Quiet mirror
lftp $_user:$_pw@$_host -e "mirror -c; exit"> /dev/null 2>&1
限速
查看與速度有關的設:
set net:limit-rate 0:0
# down:up, 0 means unlimited, bytes/second, Suffixes are supported(100k) set net:limit-rate 0:0
設定下載速度:
set net:limit-total-rate 0:1024
Script
--script=FILE write lftp commands to FILE, but don't execute them
-f script_file Execute commands in the file and exit. This option must be used alone without other arguments.
--dry-run
#!/bin/bash #### Setting _host=x.x.x.x _user=myuser _pw=mypw lftp $_user:$_pw@$_host -e "ls;exit"
TLS
Step
lftp :~> set ftp:ssl-force true
lftp :~> set ssl:verify-certificate no
lftp :~> set ftp:ssl-protect-data true;
lftp :~> connect x.x.x.x
lftp x.x.x.x:~> login <user> [pass]
Troubleshoot
ls: Fatal error: gnutls_record_recv: A record packet with illegal version was received.
可能原因
chroot_list file does exists