Skip to main content

SMTP; FTP types and working principle

Short answer

SMTP is the push protocol (TCP port 25/587) for sending email between servers. FTP uses two connections: control on port 21 and a separate data connection; types include active, passive, anonymous, authenticated, secure. It transfers files with commands like RETR/STOR after authenticating via USER/PASS.

What do you mean by SMTP? Explain the types of FTP and its working principle.

SMTP

Simple Mail Transfer Protocol (SMTP) (RFC 5321) is the application-layer protocol used to send e-mail from a user's mail client to a mail server and between mail servers. It works over TCP, port 25 for server-to-server and 587 (or 465 with TLS) for client submission. It is a text-based push protocol; receiving mail is done by POP3 or IMAP.

Mail transfer steps:

  1. User agent submits the mail to its mail server.
  2. The server finds the recipient's mail server using the DNS MX record.
  3. The server opens a TCP connection and runs the SMTP dialogue.
  4. The recipient's server stores the mail in the mailbox.

Dialogue:

S: 220 mail.example.np ready
C: EHLO pc1.example.com
S: 250 OK
C: MAIL FROM:<ram@example.com>
S: 250 OK
C: RCPT TO:<sita@example.np>
S: 250 OK
C: DATA
S: 354 End with <CRLF>.<CRLF>
C: Subject: Hello ... .
S: 250 Queued
C: QUIT
S: 221 Bye

Types of FTP

  1. Active FTP: the client opens the control connection to server port 21 and tells the server its data port (PORT command); the server connects back from port 20 to the client.
  2. Passive FTP: the client sends PASV, the server replies with a high port and the client makes the data connection too. It works behind firewalls and NAT.
  3. Anonymous FTP: public access, no account needed.
  4. Authenticated FTP: user name and password.
  5. Secure FTP: FTPS (FTP over TLS) and SFTP (over SSH).

Working principle of FTP

FTP uses a client/server model with two TCP connections.

 Client                              Server
   |---- control connection (21) ----|
   |  USER/PASS, LIST, RETR, STOR    |
   |<--- replies 220, 230, 226 ------|
   |==== data connection (20 or n) ==|
   |<===== file contents ============|
  1. The client opens a control connection to port 21 and authenticates with USER and PASS.
  2. The client issues commands such as LIST (directory), RETR (download), STOR (upload), CWD (change directory).
  3. For each transfer a separate data connection is created (active or passive mode) and closed when the transfer finishes. Control and data are separate ("out-of-band" control).
  4. The server sends a reply code (e.g. 226 Transfer complete).
  5. The session ends with QUIT.

Data may be sent in ASCII or binary mode. FTP keeps state about the session (user, current directory), unlike HTTP.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Internet and Intranet chapter 3 questions →