netpkt/ftp.rs#
Source: lib/netpkt/ftp.rs
ftp -- the control connection of the File Transfer Protocol (TCP port 21, RFC 959): command
lines, replies with their multi-line form, the host-port of PORT and of the 227 reply to PASV,
EPRT and the 229 reply to EPSV (RFC 2428), FEAT's list (RFC 2389)
Command { verb, arg } Command::parse(line) (the verb in capitals, the argument as
typed), Command::new(verb, arg), to_line() ("USER anna\r\n"; CR,
LF and NUL of the fields left out)
Reply { code, lines } to_bytes(): one line "220 text", or "211-first" ... "211 last"
(the inner lines start with a space when they could look like
the end); is_final / is_ok (1xx preliminary, 2xx done, 3xx more)
Lines cuts the bytes of a control connection into lines (CRLF, a lone
LF too), in any pieces as they arrive
ReplyReader the replies of a server from its bytes: push(bytes) -> Vec<Reply>
(a multi-line reply ends with a line of the same code and a space)
host_port(text) / fmt_host_port(ip, port) "h1,h2,h3,h4,p1,p2" (PORT's argument, 227's
numbers: host_port finds them anywhere in a reply's text)
eprt(arg) / fmt_eprt(addr, port) "|1|10.0.0.5|40001|", "|2|2001:db8::5|40001|"
epsv_port(text) / fmt_epsv(port) the "(|||port|)" of a 229 reply
PORT_FTP (21), PORT_FTP_DATA (20), verb_known
Lines are UTF-8 or ASCII; RFC 959 allows Telnet sequences, which nobody sends here. The
reply texts are the server's own words: clients go by the codes and the numbers of 227 and
229 only.
PORT_FTP: u16 = 21
/// the server's port of active data connections
PORT_FTP_DATA: u16 = 20
fn verb_known(v: &str) -> boolthe commands of RFC 959, 2389, 2428 and 3659 a dissector namesstruct Commanda command line of a clientverb: String-- in capitalsarg: String-- everything after the first space (may hold spaces: a file name)
impl Command
fn new(verb: &str, arg: &str) -> Commandfn parse(line: &str) -> Option<Command>a line without its line end; None for an empty onefn to_line(&self) -> Stringthe line on the wire, CRLF included; CR, LF and NUL of verb and argument are left out (they would end the line and start another command)struct Replya reply of a servercode: u16lines: Vec<String>-- the text of each line (without the code of the first and the last)
impl Reply
fn new(code: u16, text: &str) -> Replyfn text(&self) -> &strthe text of the first linefn is_preliminary(&self) -> bool1xx: more replies follow for this commandfn is_ok(&self) -> bool2xx: donefn is_intermediate(&self) -> bool3xx: the command waits for another (PASS after USER)fn to_bytes(&self) -> Vec<u8>the reply as bytes: "code text\r\n", or the multi-line form of RFC 959 4.2struct Linescuts a byte stream into lines
impl Lines
fn new() -> Linesfn push(&mut self, b: &[u8]) -> Vec<String>the complete lines inband what came before it, without their line endsfn pending(&self) -> usizebytes waiting for their line endstruct ReplyReaderthe replies of a server, as its bytes arrive
impl ReplyReader
fn new() -> ReplyReaderfn push(&mut self, b: &[u8]) -> Vec<Reply>the replies that are complete now; a line that is no reply is skippedfn host_port(text: &str) -> Option<(Ipv4, u16)>"h1,h2,h3,h4,p1,p2" anywhere in a text (PORT's argument; a 227 reply, where clients look for the six numbers whatever the words around them)fn fmt_host_port(ip: Ipv4, port: u16) -> Stringthe six numbers of an IPv4 address and a portfn eprt(arg: &str) -> Option<(IpAddr, u16)>EPRT's argument: a delimiter, the family (1 IPv4, 2 IPv6), the address and the portfn fmt_eprt(addr: IpAddr, port: u16) -> StringEPRT's argument for an address and a portfn epsv_port(text: &str) -> Option<u16>the port of a 229 reply: "(|||port|)" in its text (any delimiter of RFC 2428)fn fmt_epsv(port: u16) -> String"(|||port|)" for a 229 reply