: the file transfer protocol Protocolo at host interface local file system file transfer remote file system utilizes two ports: - a 'data' port (usually port 20...) - a 'command' port (port 21) SISTEMAS INFORMÁTICOS SLIDES 13 Separate control, data connections contacts the at port 21. Client obtains authorization over control connection. Client browses remote directory by sending commands over control connection. When receives a command for a file transfer, the opens a TCP data connection to (port 20). After transferring one file, the closes connection. TCP control connection port 21 TCP data connection port 20 Server opens a second TCP data connection to transfer another file. maintains state : current directory, earlier authentication : Active Mode In active mode the connects from a random port (N > 1024) to the 's command port, port 21. Then, the starts listening to port N+1 and sends the command PORT N+1 to the. The will then connect back to the 's specified data port from its local data port, which is port 20. To support the active mode, the firewall at the s side has to have the following channels - 's port 21 from anywhere (Client initiates connection) - 's port 21 to ports > 1024 (Server responds to 's control port) - 's port 20 to ports > 1024 (Server initiates data connection to 's data port) - 's port 20 from ports > 1024 (Client sends ACKs to 's data port) : Active Mode PORT 1027 : Active Mode There is a problem with active mode at the side. The doesn't make the actual connection to the data port of the --it simply tells the what port it is listening on and the connects back to the specified port on the. From the side firewall this appears to be an outside system initiating a connection to an internal -- something that is usually blocked at the firewall. 1
Active Mode: dialog example : Passive Mode testbox1: {/home/p-t/slacker/public_html} % ftp -d testbox2 Connected to testbox2.slacksite.com. 220 testbox2.slacksite.com ready. Name (testbox2:slacker): slacker ---> USER slacker 331 Password required for slacker. Password: TmpPass ---> PASS XXXX 230 User slacker logged in. ---> SYST 215 UNIX Type: L8 Remote system type is UNIX. Using binary mode to transfer files. ftp> ls ftp: setsockopt (ignored): Permission denied ---> PORT 192,168,150,80,14,178 200 PORT command successful. ---> LIST 150 Opening ASCII mode data connection for file list. drwx------ 3 slacker s 104 Jul 27 01:45 public_html 226 Transfer complete. ftp> quit ---> QUIT 221 Goodbye. Port = (14*256)+178=3762 In passive mode the initiates both connections to the, solving the problem of firewalls filtering the incoming data port connection to the from the. When opening an connection, the opens two random unprivileged ports locally (N > 1024 and N+1). The first port contacts the on port 21, but instead of sending a PORT command the will send the PASV command. The result of this is that the then opens a random unprivileged port (P > 1024) and sends the PORT P command back to the. The then initiates the connection from port N+1 to port P on the to transfer data. : Passive Mode (Firewall) Passive Mode To support passive mode, the firewall of the has to implement the following rules: 's port 21 from anywhere (Client initiates connection) 's port 21 to ports > 1024 (Server responds to 's control port) 's ports > 1024 from anywhere (Client initiates data connection to random port specified by ) 's ports > 1024 to remote ports > 1024 (Server sends ACKs (and data) to 's data port) PORT 2024 PASV Passive Mode: dialog example testbox1: {/home/p-t/slacker/public_html} % ftp -d testbox2 Connected to testbox2.slacksite.com. 220 testbox2.slacksite.com ready. Name (testbox2:slacker): slacker ---> USER slacker 331 Password required for slacker. Password: TmpPass ---> PASS XXXX 230 User slacker logged in. ---> SYST 215 UNIX Type: L8 Remote system type is UNIX. Using binary mode to transfer files. ftp> passive Passive mode on. ftp> ls ftp: setsockopt (ignored): Permission denied ---> PASV 227 Entering Passive Mode (192,168,150,90,195,149). ---> LIST 150 Opening ASCII mode data connection for file list drwx------ 3 slacker s 104 Jul 27 01:45 public_html 226 Transfer complete. ftp> quit ---> QUIT 221 Goodbye. : Active vs Passive Mode Active : command: (>1024) 21 data: (>1024) 20 Passive : command: (>1024) 21 data: (>1024) (>1024) 2
: Active vs Passive Mode commands, responses Active is beneficial to the admin, but detrimental to the side admin. The attempts to make connections to random high ports on the, which would almost certainly be blocked by a firewall on the side. Passive is beneficial to the, but detrimental to the admin. The will make both connections to the, but one of them will be to a random high port, which would almost certainly be blocked by a firewall on the side. Sample commands: sent as ASCII text over control channel USER name PASS password LIST return list of file in current directory RETR filename retrieves (gets) file STOR filename stores (puts) file onto remote host Sample return codes status code and phrase (as in HTTP) 331 Username OK, password required 125 data connection already open; transfer starting 425 Can t open data connection 452 Error writing file Access Control Commands Transfer Commands USER PASS CWD CDUP QUIT specify specify password change directory change directory to parent logout PORT PASV TYPE MODE STRU publish local data port should listen establish data representation establish transfer mode establish file structure Service Commands Replies RETR STOR STOU APPE ABOR PWD LIST retrieve file send file send file and save as unique send file and append abort previous service command print working directory transfer list of files over data link All replies are sent over control connection. Replies are a single line containing 3 digit status code (sent as 3 numeric chars). text message. Status code is used by programs, text is for humans. 3
Data Transfer Modes STREAM: file is transmitted as a stream of bytes. BLOCK: file is transmitted as a series of blocks preceded by headers containing count and descriptor code (EOF, EOR, restart marker). COMPRESSED: uses a simple compression scheme - compressed blocks are transmitted. Protocolo (E) Three major components: s. s. simple transfer protocol:. User Agent reader. composing, editing, reading messages. e.g., Eudora, Outlook, Netscape Messenger outgoing, incoming messages stored on. Electronic Mail outgoing message queue box Electronic Mail: s Mail Servers box contains incoming messages for message queue of outgoing (to be sent) messages protocol between s to send e messages : sending : receiving Electronic Mail: [RFC 821] Alice sends a message to Bob uses TCP to reliably transfer e message from to, port 25 direct transfer: sending to receiving three phases of transfer handshaking (greeting) transfer of messages closure command/response interaction commands: ASCII text response: status code and phrase messages must be in 7-bit ASCII 1) Alice uses UA to compose message and to bob@dei.uc.pt 2) Alice s UA sends message to her ; message placed in message queue 3) Client side of opens TCP connection with Bob s 1 2 3 4 4) sends Alice s message over the TCP connection 5) Bob s places the message in Bob s box 6) Bob invokes his to read message (IMAP; POP3) 5 6 4
Commands Try interaction for yourself: HELO hostname startup and give your hostname MAIL FROM: sender-address TO: recipient-address VRFY address does this address actually exist (verify) EXPN address expand this address DATA start giving you the body of the message RSET reset state and drop current message NOOP do nothing DEBUG [level] set debugging level HELP give me some help please QUIT close this connection telnet smtp_ 25 see 220 reply from enter HELO, MAIL FROM, RCPT TO, DATA, QUIT commands Sample interaction : final words S: 220 smtp.isctem.com C: HELO xpto.isctem.com S: 250 Hello xpto, pleased to meet you C: MAIL FROM: <deus@paraiso.com> S: 250 deus@paraiso.com... Sender ok C: RCPT TO: <irene@hot.com> S: 250 irene@hot.com... Recipient ok C: DATA S: 354 Enter, end with "." on a line by itself C: Irene, terás que mudar de clube C: caso queiras atingir o paraíso C:. S: 250 Message accepted for delivery C: QUIT S: 221 isctem.com closing connection uses persistent connections requires message (header & body) to be in 7-bit ASCII uses CRLF.CRLF to determine end of message Comparison with HTTP: HTTP: pull : push both have ASCII command/response interaction, status codes HTTP: each object encapsulated in its own response msg : multiple objects sent in multipart msg Mail message format Message format: multimedia extensions : protocol for exchanging e msgs RFC 822: standard for text message format: header lines, e.g., To: From: Subject: different from commands! body the message, ASCII characters only header body blank line MIME: multimedia extension, RFC 2045, 2056 additional lines in msg header declare MIME content type MIME version method used to encode data multimedia data type, subtype, parameter declaration encoded data From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data.........base64 encoded data 5
MIME types Content-Type: type/subtype; parameters Multipart Type Text plain, html Image jpeg, gif Audio basic (8-bit mu-law encoded), 32kadpcm (32 kbps coding) Video mpeg, quicktime Application other data that must be processed by reader before viewable msword, octetstream From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=startofnextpart --StartOfNextPart Dear Bob, Please find a picture of a crepe. --StartOfNextPart Content-Transfer-Encoding: base64 Content-Type: image/jpeg base64 encoded data.........base64 encoded data --StartOfNextPart Do you want the recipe? Mail access protocols access protocol sender s receiver s : delivery/storage to receiver s Mail access protocol: retrieval from POP: Post Office Protocol [RFC 1939] authorization ( <-->) and download IMAP: Internet Mail Access Protocol [RFC 1730] more features (more complex) manipulation of stored msgs on HTTP: Hot, Yahoo! Mail, etc. POP3 protocol (port 110) authorization phase commands: : declare name pass: password responses +OK -ERR transaction phase, : list: list message numbers retr: retrieve message by number dele: delete quit S: +OK POP3 ready C: bob S: +OK C: pass hungry S: +OK successfully logged on C: list S: 1 498 S: 2 912 S:. C: retr 1 S: <message 1 contents> S:. C: dele 1 C: retr 2 S: <message 1 contents> S:. C: dele 2 C: quit S: +OK POP3 signing off POP3 and IMAP IMAP POP3 Previous example uses download and delete mode. Bob cannot re-read e- if he changes. Download-and-keep : copies of messages on different s. POP3 is stateless across sessions. IMAP Keep all messages in one place: the. Allows to organize messages in folders. IMAP keeps state across sessions: names of folders and mappings between message IDs and folder name Fully compatible with Internet messaging standards, e.g. MIME. Allow message access and management from more than one computer. Allow access without reliance on less efficient file access protocols. Provide support for "online", "offline", and "disconnected" access modes * Support for concurrent access to shared boxes Client software needs no knowledge about the 's file store format. 6