LFTP Cheat Sheet: Enhance Your File Transfer Capabilities
Explore the full potential of LFTP with this detailed cheat sheet. From setting up torrent options, SSH key configurations, to mastering FXP transfers and multi-segment downloading, this guide provides all you need for efficient file management and transfer.
Install lftp
emerge --ask lftp
List all files in a tarball 'on-the-fly'
lftp -e "cat debootstrap_1.0.119~bpo10+1.tar.gz | tar -tzvf -" https://ftp.debian.org/debian/pool/main/d/debootstrap/
This is my currnet lftpd config
# -------------------------------------------------------------------------------------
# Author https://github.com/lavv17
# https://www.mail-archive.com/lftp@uniyar.ac.ru/
# http://lav.yar.ru/programs.html
# http://lav.yar.ru/hw.html# https://mail.uniyar.ac.ru/mailman/listinfo/lftp
# https://linux.overshoot.tv/wiki/lftp
# https://web.archive.org/web/20111024014512/http://tutorials.papamike.ca/pub/lftp.html
# https://web.archive.org/web/20111024014512/http://tutorials.papamike.ca/pub/lftp.html
# https://web.archive.org/web/20120605031935/http://fryth.com/lftpfaq/
# --------------------------------------------------------------------------------------
debug 5
##########################################
# Set HTTP Settings.
###########################################
set http:set-cookies true
set http:user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.9999.99 Safari/537.36"
set http:referer ''
set http:accept-language "Accept-Language: en"
##########################################
# Set SSL Settings.
###########################################
set ssl:verify-certificate no
set ssl:check-hostname no
##########################################
# Set LFTP Prompt.
###########################################
# set prompt "\[\e[0;32m\]┌┼───┤\[\e[1;33m\] [lftp] \[\e[0;36m\]\u\[\e[0;33m\]\@\[\e[0;36m\]\h \[\e[0;32m\]├───┤\[\e[0;33m\]\w\[\e[0;32m\]├───\n└┼─\[\e[1;33m\]$\[\e[0;32m\]─┤► :\[\e[0m\] "
# set prompt "\[\033[m\]|\[\033[1;35m\]\t\[\033[m\]|\[\e[1;31m\]\u\[\e[1;36m\]\[\033[m\]@\[\e[1;36m\]\h\[\033[m\]:\[\e[0m\]\[\e[1;32m\][\W]> \[\e[0m\]"
set prompt "\[\e[1;37m\]lftp\] \[\e[0;32m\]\h\] \w\] \[\e[1;37m\]>\[\e[0m\] "
##########################################
# Set FTP Settings
###########################################
set ftp:fix-pasv-address no
set ftp:passive-mode no
#set ftp:port-ipv4 your.ip.address
#set ftp:port-range minport-maxport (eg. 2000-2050)
##########################################
# Set NET Settings
###########################################
set net:reconnect-interval-base 60
set net:reconnect-interval-multiplier 1
##########################################
# Set BOOKMARK Settings
###########################################
set bmk:save-passwords yes
##########################################
# Set LOG Setting (enabled)
###########################################
set log:enabled 1
set log:level 1
set log:file "lftp.log"
set log:file/xfer "lftp-transfers.log"
set log:max-size 5242880
set log:prefix-error "ERROR: "
set log:prefix-note "NOTE: "
set log:prefix-recv "<- "
set log:prefix-send "-> "
set log:show-ctx true
set log:show-pid true
set log:show-time true
set xfer:log 1
set xfer:eta-period 3
set xfer:log-file "lftp-transfers.log"
# Active (PORT) mode settings
# This allows you to see welcome banners, directory messages, etc.
# Or you can use an even higher debug level to see all FTP messages. # debug 5
# To get a listing of all settings, type set -a, or try the lftp man page.
set ssl:verify-certificate no
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
set ssl:key-file ~/.ssh
set sftp:connect-program "ssh -a -x -i yourprivatekeyfile"
FXP: Server A > Server B
lftp -c 'open -e "mirror <server-A_dir_path> <server-B_url>" <server-A_site>'
Dump current settings
lftp -e "set;exit"
Dump all settings
lftp -e "set -a ;exit"
Multi-segment file downloading with lftp
lftp -u user,pass ftp://site.com -e 'pget -c -n 6 file'
Multi-segment directory downloading with lftp
lftp -u user,pass ftp://site.com/ -e 'mirror -c --parallel=3 --use-pget-n=5 "Some folder"'
Upload a File
lftp -e 'put /local/path/yourfile.mp4; bye' -u user,password ftp.foo.com
Connection Timeout
lftp -e 'set net:timeout 10; put /local/path/yourfile.mp4; bye' -u user,password ftp.foo.com
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
lftp -e 'set net:timeout 10; get yourfile.mp4; bye' -u user,password ftp.foo.com
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
lftp -e 'mirror -R /local/path/ /' -u user,password ftp.foo.com
Recursive Download
lftp -e 'mirror / /local/path/' -u user,password ftp.foo.com
Regular-Expression–Match Upload
lftp -e 'mirror -R -i "\.(html?|css|js)$" /local/path/ /' -u user,password ftp.foo.com
Special Characters in Username or Password
lftp -e 'put /local/path/yourfile.mp4; bye' -u user,password\!\! ftp.foo.com
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://user:password@localhost:65005/site/"
Download all files from server in 20 parallel transfers
lftp -d -e open https://extdist.wmflabs.org/dist/extensions/ -e "mirror -P 20 ."
Disable notification check
mkdir ~/.lftp
echo "set ssl:verify-certificate no" >> ~/.lftp/rc
Download all folders inside /mp3/* on ftp to mp3
lftp -e open ftp://user1:pass1:site1:port -e "mirror -c -P1 remote/path /local/path" -d
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
lftp -c "pget -n 10 http://example.com/foo.bar"
Mirrors directory to a ftp server
lftp -u login,passwd" -e "mirror reverse /my/from/dir/ /ftp/target/dir/" ftp://site.com/
Mirror a directory structure from websites with an Apache-generated file indexes
lftp -e "mirror -c" http://example.com/foobar/
Multi-segment file downloading with lftp
lftp -u "user,pass" ftp://site.com -e 'pget -c -n 6 file'
Mirror a directory structure from websites with an Apache-generated file indexes
lftp -e "mirror -c" http://example.com/foobar/
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
lftp -u "user,pass" ftp://site.com/ -e 'mirror -c parallel=3 use-pget-n=5 "Some folder"'
Gets directory and files tree listing from a FTP-server
lftp -u "user,pass" ftp://site.com/ -e "du -a;exit" > server-listing.txt
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/