SkillPilotAI

ftp (2/2)

Part 2 of ftp covers the tnftp interactive prompt: navigation and listing, transfers and resume, multi-file prompts, remote file management, transfer modes and toggles, throttling, set options, raw commands, macros, environment variables and .netrc.

149.1 How it works: control + data connections

Passive mode (tnftp default)
  1. 1.Login and all commands go over the control connection on TCP 21

  2. 2.ls or get: client sends EPSV

  3. 3.Server replies 229 (|||30002|) with a high port

  4. 4.Client opens a new data connection to that port

  5. 5.Listing or file travels on the data connection

Active mode
  1. 1.Client sends EPRT |1|192.168.169.20|42841| on the control connection

  2. 2.Server connects from port 20 to the client's port

  3. 3.Behind NAT / firewall this incoming connection is blocked

  4. 4.So tnftp defaults to passive

  • Lab: n149-client 192.168.169.20 (tnftp), n149-srv 192.168.169.10 (vsftpd :21, pyftpdlib :2121).

149.2 Navigation and listing

  • pwd / cd / cdup work on the server; lpwd / lcd on the local machine (lcd with no arg = home).
  • dir is a long listing (ls is a synonym); nlist gives names only.
  • ls . file saves the listing to a local file; dir . "|head -3" pipes it to a local command.
  • mlsd / mlst give machine-readable facts (size, modify); vsftpd does not support them, pyftpdlib does.
  • mdir / mls list several paths; pdir / pls use the pager.
Output
user student LAB-ONLY-149pwdcd docscduplcd /tmplpwddir docsnlist
Output
ftp> dir docs229 Entering Extended Passive Mode (|||30007|)150 Here comes the directory listing.-rw-r--r--    1 1000     1000            6 Nov 09 06:00 guide.txt226 Directory send OK.
Output
ls . listing.txtdir . "|head -3"mlsd            # vsftpd: not supported# new session: pyftpdlib on port 2121ftp -n 192.168.169.10 2121mlsd docsmlst a.txt
Output
$ ftp -n 192.168.169.10 2121220 pyftpdlib 1.5.9 ready.ftp> mlsd docsmodify=20261109060011;perm=r;size=6;type=file;unique=58g2a9d2; guide.txtftp> mlst a.txt250-Listing "/a.txt": modify=20260115103000;perm=r;size=6;type=file;unique=58g2a9b4; /a.txt250 End MLST.

149.3 Transfers

CommandMeaning
get / recv rfile [lfile]Download (- = stdout, "|cmd" = pipe)
put / send lfile [rfile]Upload
append lfile rfileAdd a local file to the end of a remote file
newer rfileDownload only if the remote file is newer
reget rfileResume a partial download (350 restart reply)
restart NOffset for the next get/put (needs existing local file)
fget listfileDownload every file named in a list
mget / mreget / mputMulti-file get / get with resume / put
page / less / moreDownload and show in the pager
Output
get a.txtget b.txt -get readme.txt "|wc -l"recv c.txt copy.txtput up.txtsend up.txt sent.txtappend extra.txt up.txtget up.txt -
Output
ftp> append extra.txt up.txtlocal: extra.txt remote: up.txt14 bytes sent in 00:00 (22.59 KiB/s)ftp> get up.txt -upload from clientone more line33 bytes received in 00:00 (78.60 KiB/s)
Output
newer a.txt!touch -d 2025-01-01 a.txtnewer a.txtget big.bin!truncate -s 1048576 big.binreget big.binfget filelist.txtpage readme.txt
Output
ftp> fget filelist.txtlocal: a.txt remote: a.txt226 Transfer complete.local: c.txt remote: c.txt226 Transfer complete.ftp> page readme.txtreadme line 1readme line 2readme line 3

149.4 Multi-file prompt answers

  • With prompt on, mget/mput ask for each file.
  • y yes, n skip, ? help, a yes to all remaining, q abort the whole command, p yes and switch prompting off.
  • prompt off before mget avoids all questions.
Output
mget *.txtyn?amget notes.md dos.txtqmput *.logpprompt offmget *.md

149.5 Remote file management

  • mkdir / rmdir / delete / mdelete manage remote files; rename sends RNFR + RNTO.
  • chmod 600 uses SITE CHMOD; umask 077 made the next upload owner-only (-rw-------).
  • size and modtime work without downloading; system shows the OS type; features shows FEAT; rstatus shows server status.
  • idle is unsupported on vsftpd: 500 Unknown SITE command.
Output
mkdir backuprmdir backuprename up.txt upload.txtchmod 600 upload.txtdelete sent.txtprompt offmdelete *.logumask 077put extra.txt private.txtdir private.txtsize big.binmodtime a.txtsystemfeaturesrstatus
Output
ftp> umask200 Your current UMASK is 022ftp> umask 077200 UMASK set to 077ftp> put extra.txt private.txt226 Transfer complete.ftp> dir private.txt-rw-------    1 1000     1000           14 Nov 09 06:01 private.txt

149.6 Transfer modes and toggles

  • ascii strips CR from line ends (cr toggle on); binary = image keeps bytes unchanged.
  • mode, struct and form support only one value (stream, file, non-print).
  • passive toggles PASV/active; passive auto falls back to active; epsv4 off uses classic PASV (227) instead of EPSV.
  • sunique (STOU) saves notes.md.1 instead of overwriting; runique does the same locally (a.txt.1).
  • preserve keeps the server's mtime (on); case, nmap, ntrans map file names; status shows everything.
Output
typeasciiget dos.txt!od -c dos.txtbinarymode streamdebugpassivepassive autoepsv4 offls docs
Output
ftp> mode streamWe only support stream mode, sorry.ftp> epsv4 offEPSV/EPRT on IPv4 off.ftp> ls docs---> PASV227 Entering Passive Mode (192,168,169,10,117,51).---> LIST docs150 Here comes the directory listing.
Output
ftp> statusPassive mode: on; fallback to active mode: off.Mode: stream; Type: binary; Form: non-print; Structure: file.Verbose: on; Bell: off; Prompting: on; Globbing: on.Store unique: on; Receive unique: on.Preserve modification times: on.Case: off; CR stripping: on.Hash mark printing: off; Mark count: 1024; Progress bar: off.Use of EPSV/EPRT cmds for IPv4: on.Version: tnftp 20210827

149.7 Output, throttling and buffers

  • hash 256k prints one # per 256 KB; progress shows a bar; bell rings after each transfer; verbose off is silent.
  • rate get 512k limited a 2 MB file to exactly 4 s; rate all shows both directions; rate get 0 removes the limit.
  • sndbuf / rcvbuf / xferbuf set socket buffers; byte counts accept k, m, g.
Output
hash 256kget big.bin           # 8 marks for 2 MBxferbuf 1mrate get 512kprogressget big.bin           # exactly 4 srate get 0get big.bin big2.bin
Output
ftp> xferbuf 1mSocket buffer sizes: send 1048576, receive 1048576.ftp> rate get 0Get transfer rate throttle: off; maximum: 0; increment 1024.ftp> get big.bin big2.bin226 Transfer complete.2097152 bytes received in 00:00 (335.73 MiB/s)

149.8 set / unset options

  • set alone shows all options; unset clears one.
  • anonpass (anonymous password), ftp_proxy / http_proxy / https_proxy / no_proxy for URL fetches, pager.
  • prompt / rprompt with %c (last dir part), %/ (full path), %M / %m (host), %n (user).
  • sslnoverify 1 turns off certificate checks: testing only.
Output
setset anonpass lab149@example.comset http_proxy http://192.168.169.1:3128set no_proxy localhost,192.168.169.10set pager headset prompt "%c> "cd docsunset http_proxyunset prompt

149.9 Raw commands, macros and help

  • quote sends any raw command (SYST, FEAT); literal is a Windows ftp command and is invalid in tnftp.
  • site runs SITE commands; rhelp asks the server for its command list; remopts sets options like MLST facts.
  • proxy opens a second connection for server-to-server copy (usually blocked today).
  • macdef name defines a macro ending at a blank line; $1 is the first argument; run with $ name args.
  • help / ? describe a command; usage shows its syntax; ! runs a local shell command.
Output
quote SYSTquote FEATliteral NOOP          # Windows command: invalid in tnftpsite CHMOD 755 run.shrhelp
Output
ftp> rhelp214-The following commands are recognized. ABOR ACCT ALLO APPE CDUP CWD  DELE EPRT EPSV FEAT HELP LIST MDTM MKD MODE NLST NOOP OPTS PASS PASV PORT PWD  QUIT REIN REST RETR RMD  RNFR RNTO SITE SIZE SMNT STAT STOR STOU STRU SYST TYPE USER XCUP XCWD XMKD XPWD XRMD214 Help OK.
Output
macdef grabbinaryget $1!ls -l $1 $ grab c.txthelp rateusage get
Output
ftp> help raterate       	set transfer rate limit (in bytes/second)ftp> usage getusage: get remote-file [local-file]

149.10 Environment variables and .netrc

  • ~/.netrc: machine / login / password give auto-login; macdef init runs right after login; default matches all other hosts.
  • tnftp refuses auto-login if .netrc is readable by others (chmod 600).
  • FTPMODE (active / passive / auto default / gate), FTPPROMPT, FTPANONPASS, NETRC (alternate file), PAGER, FTPUSERAGENT, FTPSSLNOVERIFY.
Output
machine 192.168.169.10  login student  password LAB-ONLY-149macdef initcd docspwd default login anonymous password lab149@example.com
Terminal
FTPMODE=active ftp -d 192.168.169.10FTPPROMPT='%m %/> ' ftp 192.168.169.10FTPANONPASS=student149@example.com ftp -a anon-ftpNETRC=/lab/work.netrc ftp 192.168.169.10PAGER='head -3' ftp -n 192.168.169.10
Output
$ NETRC=/lab/work.netrc ftp 192.168.169.10331 Please specify the password.230 Login successful.ftp> pwdRemote directory: /home/student

149.11 Comparison: ASCII vs binary

PointASCIIBinary (image)
Line endingsConverted (CR stripped)Unchanged
Use forPlain text fileszip, iso, images, exe, everything else
RiskCorrupts binary filesNone

149.12 Common mistakes

  • Transferring archives or images in ASCII mode: the file gets corrupted.
  • Typing y 100 times in mget: use prompt off or answer a.
  • Using literal in tnftp: use quote.
  • Thinking PASS XXXX in debug is encryption: the password crosses port 21 in plain text; use SFTP/FTPS.
  • A world-readable .netrc: auto-login is refused.

149.13 Interview tips

  • FTP: commands on TCP 21, data on a separate connection; passive = client connects to a server port (229/227), active = server connects from port 20.
  • ASCII converts line endings, binary keeps bytes: always binary for non-text.
  • Resume with reget (REST + 350); throttle with rate get/put.
  • Automate with .netrc + macdef init, or macros with $1 arguments.