SkillPilotAI

lftp (3/3)

The last part of lftp covers its remaining settings groups: ftp (passive/active, EPSV, FEAT), FTPS/SSL with a real certificate error and its correct fix, http/hftp through a proxy, log, mirror, net, torrent, xfer and the environment variables. These settings decide whether a transfer script is secure, fast and predictable.

152.1 Why is it used?

  • ftp:passive-mode, prefer-epsv and the FEAT/MLSD options make lftp work with NAT, firewalls and odd servers.
  • ssl:* options make FTPS trust the right CA instead of failing or trusting everything.
  • hftp:proxy sends FTP through an HTTP proxy when direct FTP is blocked.
  • net:* (timeout, max-retries, limit-rate) and xfer:* (clobber, temp files) make scripts predictable.
  • LFTP_HOME and proxy environment variables give defaults without editing every command.

152.2 How it works: passive vs active FTP

  • Lab: lftp client 192.168.172.20, server lab-ftp 192.168.172.10 (vsftpd on 21, plain FTP also on 2121, Python http server and a lab proxy on 3128).
  • Passive (default): client sends PASV, server replies 227 with a high port, the client opens the data connection.
  • Active (passive-mode off): client sends PORT with its own IP and port, the server connects back from port 20, which client-side NAT/firewalls can block.
  • prefer-epsv yes: EPSV instead of PASV; the 229 reply carries only the port (no IP).
Passive mode download (default)
  1. 1.Client 192.168.172.20 logs in to 192.168.172.10:21

  2. 2.Client sends PASV

  3. 3.Server: 227 Entering Passive Mode (high port, e.g. 30000)

  4. 4.Client itself opens the data connection to that port

  5. 5.RETR report.txt -> 226 Transfer complete

Active mode reverses step 4: the server connects from port 20 to the client

Terminal
lftp -d -c 'open -u student,LabOnly152 lab-ftp  set ftp:ssl-allow no  get report.txt'lftp -d -c 'open -u student,LabOnly152 lab-ftp  set ftp:ssl-allow no  set ftp:passive-mode off  get report.txt'
Output
$ lftp -d -c '... passive-mode off ... get report.txt'---> PORT 192,168,172,20,171,197<--- 200 PORT command successful. Consider using PASV.---> RETR report.txt<--- 150 Opening BINARY mode data connection for report.txt (29 bytes).<--- 226 Transfer complete.

152.3 ftp settings: login, proxy, features

  • ftp:use-feat no skips FEAT and starts directly with AUTH TLS.
  • ftp:use-mlsd is yes by default, but vsftpd's FEAT list has no MLST, so lftp still uses LIST.
  • fix-pasv-address / ignore-pasv-address fix a wrong IP in the 227 reply behind NAT.
  • use-fxp copies directly server-to-server; web-mode disconnects after every transfer.
Output
$ lftp -d -c '... use-mlsd yes; ls'---> FEAT<---  EPSV<---  MDTM<---  REST STREAM<---  SIZE<---  TVFS<---  UTF8<--- 211 End---> LIST<--- 226 Directory send OK.
SettingMeaning
ftp:anon-user, anon-passAnonymous login (lftp@)
ftp:passive-modeon = PASV, off = PORT
ftp:prefer-epsvEPSV instead of PASV
ftp:fix-/ignore-pasv-addressFix or ignore the IP in the PASV reply
ftp:proxy, use-hftpProxy URL; hftp or CONNECT
ftp:sync-modeOne command at a time
ftp:use-feat, use-mlsdUse FEAT; MLSD for listings
ftp:use-mode-zMODE Z compression
ftp:rest-stor, use-size, use-mdtmResume, size, file times
ftp:timezone, charsetLIST time zone, charset
ftp:use-fxpServer-to-server copy
ftp:web-modeDisconnect after each transfer

152.4 FTPS / SSL: the real certificate error

  • The lab certificate is signed by a self-signed 'n152 Lab CA'; lftp verifies certificates by default.
  • Result: 'unable to get local issuer certificate'. The name lab-ftp matched, but the issuer is not trusted.
  • Quick (test-only) fix: ssl:verify-certificate no, which accepts any certificate, even a fake one.
  • Correct fix: ssl:ca-file with the lab CA's public certificate; then PROT P encrypts data too.
Output
$ lftp -d -c '... ls'---> AUTH TLS<--- 234 Proceed with negotiation.Certificate depth: 0; subject: /CN=lab-ftp; issuer: /CN=n152 Lab CAERROR: Certificate verification: unable to get local issuer certificate (63:64:BC:1B:E9:E2:9D:09:E6:73:25:4A:21:B0:18:D4:DF:2F:8F:90)Certificate verification: subjectAltName: ‘lab-ftp’ matched
FTPS certificate check and fix
  1. 1.Client sends AUTH TLS, server: 234 Proceed with negotiation

  2. 2.Server presents CN=lab-ftp, issuer CN=n152 Lab CA

  3. 3.Default: CA not in trusted list -> unable to get local issuer certificate

  4. 4.Fix: set ssl:ca-file /lab/lab-ca.crt

  5. 5.Chain verified (depth 1 CA, depth 0 lab-ftp) -> 230 Login successful

  6. 6.PROT P -> 200 PROT now Private (data encrypted too)

Terminal
lftp -d -c 'open -u student,LabOnly152 lab-ftp  set ssl:ca-file /lab/lab-ca.crt  ls'
Output
---> AUTH TLSCertificate depth: 1; subject: /CN=n152 Lab CA; issuer: /CN=n152 Lab CACertificate depth: 0; subject: /CN=lab-ftp; issuer: /CN=n152 Lab CA<--- 230 Login successful.---> PROT P<--- 200 PROT now Private.<--- 226 Directory send OK.

152.5 ssl-allow, ssl-force, ssl-protect-data

SettingWhat happened in the lab
ftp:ssl-allow noAUTH TLS skipped; the PASS line shows the password in clear text
ftp:ssl-force yesNo TLS = no login; the plain server on 2121 was refused
ftp:ssl-protect-data noPROT C: control is encrypted but the file travels in clear
ssl:verify-certificate noListing works but any certificate is trusted (test only)
ssl:ca-fileTrusted CA file: the correct fix
ssl:check-hostnameHost name must match the certificate
ssl:key-file, cert-fileClient key and certificate
ssl:crl-file, priority, use-sniRevoked certs, TLS versions, SNI
Output
$ lftp -d -c '... ssl-protect-data no ... get report.txt'---> AUTH TLS<--- 234 Proceed with negotiation.---> PROT C<--- 200 PROT now Clear.---> RETR report.txt<--- 226 Transfer complete.

152.6 http, https and hftp (FTP over an HTTP proxy)

  • lftp can list and download over http://; http:user-agent changes the User-Agent header in HEAD/GET.
  • hftp = FTP over HTTP: the client sends GET with the full ftp:// URL to the proxy; the proxy logs in to FTP and returns the listing in an HTTP response.
  • Without hftp:proxy: 'ftp over http cannot work without proxy'.
Terminal
lftp -c 'open hftp://192.168.172.10/; ls'lftp -c '  set hftp:proxy http://192.168.172.10:3128  open -u student,LabOnly152 hftp://lab-ftp/  cls -l'
Output
open: Fatal error: ftp over http cannot work without proxy, set hftp:proxy.ls: Not connected [n152-srv]$ cat /tmp/proxy.logproxy: HEAD ftp://student@lab-ftp/ UA=lftp/4.9.2proxy: GET ftp://student@lab-ftp/ UA=lftp/4.9.2proxy: HEAD ftp://student@lab-ftp/big.bin;type=i UA=lftp/4.9.2proxy: HEAD ftp://student@lab-ftp/site/;type=i UA=lftp/4.9.2

152.7 log and mirror settings

  • log:enabled/xfer yes (closure /xfer = only the transfer log) + log:file/xfer writes one line per transfer.
  • mirror:parallel-transfer-count 4 made a 4-file mirror take 2.53 s instead of about 7.5 s (at 50K per connection).
  • Other mirror defaults: exclude-regex, include-regex, order, sort-by, use-pget-n, set-permissions, skip-noaccess.
Output
$ cat /lab/xfer.log2026-11-09 06:16:09 ftp://student@lab-ftp/%2Fhome/student/report.txt -> /lab/dl/report.txt 0-29 110 B/s2026-11-09 06:16:09 ftp://student@lab-ftp/%2Fhome/student/big.bin -> /lab/dl/big.bin 0-2097152 20.03 MiB/s

152.8 net: rate limits, timeout and retries

  • net:limit-rate 500K is per connection: the 2 MB file took 3.83 s instead of under half a second; limit-total-rate covers all connections.
  • Defaults are net:timeout 5m and max-retries 1000, so a dead host can hang a script for a very long time.
  • With timeout 2, max-retries 3 and reconnect-interval-base 3, lftp gave up after about 8 seconds.
Retry loop against a dead IP
  1. 1.Client sends SYN to 192.168.172.99:21 (nothing lives there)

  2. 2.No reply within net:timeout (2 s)

  3. 3.'Timeout - reconnecting', wait reconnect-interval-base (3 s)

  4. 4.Try again (gap grows with the multiplier, max reconnect-interval-max)

  5. 5.After max-retries (3): Fatal error: max-retries exceeded

Terminal
lftp -d -c 'set net:timeout 2  set net:max-retries 3  set net:reconnect-interval-base 3  set net:reconnect-interval-multiplier 1  open -u student,LabOnly152 192.168.172.99  ls'
Output
06:16:34 **** Socket error (Host is unreachable) - reconnecting06:16:36 ---- Connecting to 192.168.172.99 (192.168.172.99) port 2106:16:38 **** Timeout - reconnecting06:16:38 ls: Fatal error: max-retries exceeded

152.9 xfer and torrent settings

  • xfer:clobber is off: the second get of the same file fails with 'file already exists' and exit 1; clobber on overwrites.
  • xfer:use-temp-file yes downloads to .in.big.bin and renames to big.bin at the end, so a half file never looks complete.
  • xfer:make-backup keeps the old file; auto-rename (off) trusts server names; verify-command checks a file after transfer.
  • torrent:* (port-range 6881-6889, max-peers, use-dht, stop-on-ratio, seed-max-time 2h) were not run: they need internet peers.
Output
$ sleep 2; ls -la | grep bin-rw-r--r--    1 root     root       1392614 Nov  9 06:16 .in.big.bin$ wait; ls -la | grep bin-rw-r--r--    1 root     root       2097152 Nov  9 06:15 big.bin

152.10 Environment variables

  • LFTP_HOME points to another config folder; its rc file (here with ssl:ca-file and timeout) loads on every start.
  • http_proxy sets both http:proxy and hftp:proxy; an http:// URL in ftp_proxy sets only hftp:proxy.
  • LFTP_PASSWORD (with --env-password) keeps the password off the command line; ~/.netrc gives a default login.
Output
$ export ftp_proxy=http://192.168.172.10:3128$ lftp -c 'set -a' | grep -E ':proxy 'set ftp:proxy ""set hftp:proxy http://192.168.172.10:3128set http:proxy ""
VariableEffect
EDITOR / PAGER / SHELLedit command, more/zmore, ! command
http_proxy, https_proxyhttp/hftp/https proxy
ftp_proxyftp:proxy (http:// = hftp)
no_proxynet:no-proxy
LFTP_HOMEConfig dir (default ~/.lftp)
LFTP_PASSWORDPassword for --env-password
LS_COLORScolor:dir-colors
~/.netrcDefault login/password

152.11 Common mistakes

  • Fixing a certificate error with ssl:verify-certificate no in production: it also accepts a fake certificate.
  • Believing FTPS = everything encrypted: PROT C sends data in clear, ssl-allow no sends PASS in clear.
  • Leaving default timeout/retries in scripts: a dead host keeps the job retrying for a long time.
  • Forgetting that net:limit-rate is per connection, not total.

152.12 Interview tips

  • Passive (default) = client opens the data connection, NAT friendly; active = PORT, server connects back from port 20.
  • Internal-CA error 'unable to get local issuer certificate': fix with ssl:ca-file company-ca.crt, not verify no.
  • hftp needs hftp:proxy; the proxy does the FTP login and returns HTTP.
  • For scripts: set net:timeout, net:max-retries and xfer:use-temp-file for predictable behaviour.