lftp | Cheatsheet¶
lftp is a command-line program client for several file transfer protocols.
lftp is designed for Unix and Unix-like operating systems. It was developed by Alexander Lukyanov
,
and is distributed under the GNU General Public License
on a professional level, LFTP is becoming a super-reliable option for me when automating FTP transfers with script.
LFTP is a more robust FTP client than just plain FTP or cURL. Unlike those clients, it retries a few times when transmission fails, has mirroring features, and supports simultaneous multi-file transfers, recursion, and Regular-Expression matches. Speed, from what I've experienced, is identical.
Customize lftp prompt line style
Torrent settings¶
set torrent:ip ""
set torrent:ipv6 ""
set torrent:max-peers 60
set torrent:port-range 6881-6889
set torrent:retracker ""
set torrent:seed-max-time 30d
set torrent:seed-min-peers 3
set torrent:stop-on-ratio 2.0
set torrent:use-dht yes
Add ssh key in either way in lftprc¶
FXP: Server A
> Server B
¶
Dump current settings¶
Dump all settings¶
Multi-segment file downloading with lftp¶
Multi-segment directory downloading with lftp¶
Upload a File¶
Connection Timeout¶
Active Mode¶
For what it's worth, Active mode -- older, stinkier, and won't go through your firewall:
lftp -e 'set ftp:passive-mode false; set net:timeout 10; put /local/path/yourfile.mp4; bye' -u user,password ftp.foo.com
Download¶
If you need to put it in a specific local directory¶
lftp -e 'set net:timeout 10; get yourfile.mp4 -o /local/path/yourfile.mp4; bye' -u user,password ftp.foo.com
Recursive Upload¶
Recursive Download¶
Regular-Expression–Match Upload¶
Non-Recursive¶
Deploy only root-level files, not the entire directory tree. The -r
switch disables recursion. In this example, we are also only deploying HTML
, CSS
, and JavaScript
JavaScript¶
Special Characters in Username or Password¶
FXP Transfer: site 1 > site2¶
lftp -d -c open -e "mirror -P15 \
"ftp://user:password@host:port/path" \
'ftp://user:password@host:port/path'
FXP Transfer: site 1 > site2¶
lftp -e "mirror -I googleAnalytics-master-dfd9155.tar.gz \
https://extdist.wmflabs.org/dist/extensions ftp://wuseman:odemnn@localhost:65005/site/"
Download all files from server in 20 parallel transfers¶
Disable notification check¶
Download all folders inside /mp3/* on ftp to mp3¶
FXP Between SITE 1 and SITE 2 with 20 threads at same time¶
lftp -e "set ftp:use-fxp true ;mirror -R -P20 ftp://user1:pass1:site1:port:/path \
ftp://user1:pass1:site1:port:/path" -d
Use lftp to multi-threaded download files from websites¶
Mirrors directory to a ftp server¶
Mirror a directory structure from websites with an Apache-generated file indexes¶
Multi-segment file downloading with lftp¶
Mirror a directory structure from websites with an Apache-generated file indexes¶
Backup sda partition to ftp ( using pipes and gziped backup )¶
dd if=/dev/sda bs=2048 conv=noerror,sync | gzip -fc | lftp -u user,passwd domain.tld -e "put /dev/stdin -o backup-$(date +%Y%m%d%H%M).gz; quit"
Fastest segmented parallel sync of a remote directory over ssh¶
lftp -u user,pwd -e "set sftp:connect-program 'ssh -a -x -T -c arcfour -o Compression=no'; mirror -v -c --loop --use-pget-n=3 -P 2 /remote/dir/ /local/dir/; quit" sftp://remotehost:22
Multi-segment directory downloading with lftp¶
Gets directory and files tree listing from a FTP-server¶
!!! Resource(s)
* <http://lftp.yar.ru/lftp-man.html>
* <http://mewbies.com/lftp/lftp.html#scripts>
* <https://web.archive.org/web/20220331040412/http://www.russbrooks.com/2010/11/19/lftp-cheetsheet>
* <https://dade2.net/kb/complete-lftp-command-tutorial/>
* <https://www.nr1.nu/linux-shell/network/lftp/>
* <https://web.archive.org/web/20080309195640/http://tutorials.papamike.ca/pub/lftp.html>
* <https://www.mail-archive.com/lftp@uniyar.ac.ru/>