The TCP/IP Guide - Version 3.0 (Contents) ` 1329 _ © 2001-2005 Charles M. Kozierok. All Rights Reserved.
Consider what is happening in the case of an active data connection as described in the
example above. From the perspective of the client, there's an established control
connection from the client's port 1678 to the server's port 21. But the data connection is
initiated by the server. So the client sees an incoming connection request to port 1678 (or
some other port). Many clients are suspicious about receiving such incoming connections,
since under normal circumstances clients establish connections, they don’t respond to
them. Since incoming TCP connections can potentially be a security risk, many clients are
configured to block them using firewall hardware or software.
Why not just make it so the client always accepts connections to the port number one
above the ephemeral number used for the control connection? The problem here is that
clients often use different port numbers for each transfer by using the PORT command. And
why is this done? Because of the rules of TCP. As I describe in the section on TCP, after a
connection is closed, a period of time must elapse before the port can be used again, to
prevent mixing up consecutive sessions. This would cause delays when sending multiple
files one after the other, so to avoid this, clients usually use different port numbers for each
transfer. This is more efficient, but means a firewall protecting the client would be asked to
accept incoming connections that appear to be going to many unpredictable port numbers.
The use of passive connections largely eliminates this problem. Most firewalls have a lot
more difficulty dealing with incoming connections to odd ports than outgoing connections.
RFC 1579, Firewall-Friendly FTP, discusses this issue in detail. It recommends that clients
use passive data connections by default instead of using normal connections with the
PORT command, to avoid the port-blocking problem.
Of course, passive data connections don't really eliminate the problem, they just push it off
onto servers. These servers now must face the issue of incoming connections to various
ports. Still, it is, generally speaking, easier to deal with security issues on a relatively
smaller number of servers than a large number of clients. FTP servers must be able to
accept passive mode transfers from clients anyway, so the usual approach is to set aside a
block of ports for this purpose, which the server's security provisions allow to accept
incoming connections, while blocking incoming connection requests on other ports.
Note: As an aside, it is that it is a significant violation of the layering principle of
networks to pass IP addresses and port numbers in FTP commands such as
PORT and PASV and the replies to them. This isn’t just a philosophical issue:
applications aren't supposed to deal with port numbers, and this creates issues when
certain lower-layer technologies are used. For example, consider the use of Network
Address Translation, which modifies IP addresses and possibly port numbers. In order to
prevent NAT from “breaking” when FTP is used, special provision must be made to handle
the protocol.