Reading — step 1 of 5
Read
~1 min readActive vs Passive
Active Mode
In active mode, the server initiates the data connection back to the client.
C → S: PORT 192,168,1,5,4,57 (client tells server its IP + port = 4*256+57 = 1081)
S → C: 200 PORT command successful
C → S: RETR file.txt
S → C: 150 Opening data connection
S → C: [opens TCP connection from server's port 20 to client's 192.168.1.5:1081]
S → C: ... file data ...
S: 226 Transfer complete
PORT format: h1,h2,h3,h4,p1,p2 where the IP is h1.h2.h3.h4 and port is p1*256+p2.
Active mode worked well in 1980s LANs. Today, problems:
- Client is usually behind NAT. Server cannot connect TO a client.
- Client firewalls block inbound connections.
Even where it works, it's invasive: server scanning client's listening port.
Server's view:
- Receive PORT command. Parse client's endpoint.
- Bind a local port (typically 20 — the data port).
- On RETR/STOR/LIST: open new TCP connection to the announced endpoint.
- Transfer data.
- Close connection (sender side closes after sending; signals end of file).
EPRT (extended PORT, RFC 2428) supports IPv6:
EPRT |2|2001:db8::1|9000|
Family (1=IPv4, 2=IPv6), address, port.
When does active mode still make sense?
- Inside a single trusted network (no NAT).
- Server-initiated jobs that need to push files to clients.
- Almost never on the internet.
For internet usage: passive mode is the answer.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…