Moving files and delivering email were among the first uses of the internet. Each has its own long-established protocols.
File Transfer Protocol (FTP)
FTP transfers files between a client and a server. It uses two TCP connections: a control connection on port 21 for commands (USER, PASS, LIST, RETR to download, STOR to upload, QUIT) and replies, kept open for the whole session; and a separate data connection for each file or listing, on port 20 in active mode (the server connects back to the client) or on a port chosen by the server in passive mode (the client connects, which works better through firewalls and NAT). Transfers may be in ASCII or binary mode. Plain FTP sends passwords and data unencrypted, so secure versions are used today: FTPS (FTP over TLS) and SFTP (file transfer over SSH, port 22). TFTP is a very simple version over UDP, used to boot devices.
Definition: SMTP. The Simple Mail Transfer Protocol, the push protocol that sends email from a client to its mail server and between mail servers, using TCP port 25 (587 for submission).
SMTP
Email uses several components: the user agent (mail client such as Thunderbird or a webmail page), mail servers holding mailboxes, and protocols to send and to retrieve. SMTPpushes mail from the sender's user agent to the sender's mail server (submission, port 587 with authentication and TLS), and then from server to server (port 25). The sending server finds the recipient's mail server through the MX record in DNS. An SMTP session uses commands such as HELO/EHLO, MAIL FROM, RCPT TO, DATA (followed by the message, ending with a line containing only a dot) and QUIT, with numbered replies such as 250 OK and 354 Start mail input. SMTP was designed for 7-bit text, so MIME encodes attachments, images and other languages.
POP3 and IMAP
To read mail, the recipient's user agent pulls it from the mail server. POP3 (Post Office Protocol 3), on port 110 (995 with TLS), normally downloads messages to one device and deletes them from the server; it is simple and works offline, but mail is not synchronised across devices. IMAP (Internet Message Access Protocol), on port 143 (993 with TLS), keeps mail on the server, with folders, read and unread flags and search, all synchronised across every device — the choice for phones, laptops and webmail today. Webmail such as Gmail uses HTTPS between the browser and the provider, which uses SMTP to exchange mail with other servers.
Table 4.2: Mail and file transfer protocols
| Protocol | Purpose | Port | Direction |
|---|---|---|---|
| FTP | File transfer | 21 control, 20 data | Both |
| SMTP | Send mail | 25, 587 | Push |
| POP3 | Retrieve, download | 110, 995 | Pull |
| IMAP | Retrieve, keep on server | 143, 993 | Pull and sync |
Example 4.2: An SMTP session
Problem: Show the main steps of an SMTP session in which ashish@college.edu sends a short message to riya@mail.org, and state how Riya reads it on her phone and laptop.
Solution:
- The client connects to the server and sends EHLO; the server replies 250.
- MAIL FROM:<ashish@college.edu> and RCPT TO:<riya@mail.org>, each answered 250.
- DATA, reply 354; the client sends the headers and body, ending with a single dot; reply 250 queued.
- QUIT ends the session. The server delivers to mail.org's server using its MX record.
- Riya uses IMAP, so both devices show the same mailbox.
Result: SMTP pushes the message; IMAP lets Riya read it on any device.
session = [
("S", "220 mail.college.edu ready"),
("C", "EHLO laptop.college.edu"), ("S", "250 Hello"),
("C", "MAIL FROM:<ashish@college.edu>"), ("S", "250 OK"),
("C", "RCPT TO:<riya@mail.org>"), ("S", "250 OK"),
("C", "DATA"), ("S", "354 End data with <CR><LF>.<CR><LF>"),
("C", "Subject: CN notes"), ("C", ""),
("C", "Unit IV notes are ready."), ("C", "."),
("S", "250 Queued"), ("C", "QUIT"), ("S", "221 Bye")]
for who, line in session:
print(("client: " if who == "C" else "server: ") + line)
Output
server: 220 mail.college.edu ready
client: EHLO laptop.college.edu
server: 250 Hello
client: MAIL FROM:<ashish@college.edu>
server: 250 OK
client: RCPT TO:<riya@mail.org>
server: 250 OK
client: DATA
server: 354 End data with <CR><LF>.<CR><LF>
client: Subject: CN notes
client:
client: Unit IV notes are ready.
client: .
server: 250 Queued
client: QUIT
server: 221 Bye
Common mistakes
- Thinking SMTP is used to read mail. It only sends; POP3 and IMAP retrieve.
- Forgetting that FTP needs a separate data connection besides the control connection.
- Using plain FTP or POP3 on untrusted networks; passwords travel in clear text.
Key takeaways
- FTP: control on port 21, data on port 20 or passive ports; use FTPS or SFTP.
- SMTP pushes mail (ports 25 and 587); MIME carries attachments.
- POP3 downloads and usually deletes; IMAP keeps mail synchronised on the server.
- MX records in DNS locate a domain's mail server.
Practice questions
- Which protocol keeps email synchronised across devices?
- Why does FTP use two connections?
- What is MIME used for?
Answers to the practice questions
- IMAP.
- One carries commands (control) and the other carries file data.
- Encoding attachments, images and non-ASCII text in email.
Sources
- Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit IV
