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