FTP Active and Passive mode difference

+1 vote
asked Oct 18, 2010 by Rebex KB (8,330 points)
edited Jun 15, 2012

What's the difference between active and passive mode in FTP?

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Oct 19, 2010 by Martin Vobr (12,940 points)
edited Jun 15, 2012
 
Best answer

FTP uses two communication channels: control connections and data connection.

Control connection

  • clients connects to server's port 21
  • remains open for the duration of the session
  • used for sending commands such as change directory, login etc.

Data connection

  • new connection is opened and closed for each data transfer
  • used for upload, download and directory listing

Active and Passive mode

Active and passive mode determines how the data connection is opened.

Active mode

In active mode FTP server connects to the client. This used to be default mode in the past, however, this is not very firewall friendly.

Typical communication goes as follows:

Client: PORT 192,168,1,2,251,248
Server: 200 PORT command successful.
Client: RETR readme.txt
Server: 150 Opening BINARY mode data connection for /readme.tx(1884 bytes).
Server: 226 Transfer complete.

Passive mode

In passive mode FTP client connects to the server. This is default when connecting to the FTP server from a web browser.

Typical communication goes as follows:

Client: PASV
Server: 227 Entering Passive Mode (192,168,1,1,9,87).
Client: RETR readme.txt
Server: 125 Data connection already open; Transfer starting.
Server: 226 Transfer complete.

Active and Passive mode in Rebex FTP

Following code enables active mode in Rebex FTP:

Ftp ftp = new Ftp();
ftp.Passive = false;

Following code enables passive mode in Rebex FTP:

Ftp ftp = new Ftp();
ftp.Passive = true; // this is default
...