Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In protocol design, why would you ever use 2 ports?

When a TCP Server does a socket accept on a port, it gets a new socket to work with that Client.
The accepting socket remains valid for that port and can accept further clients on that port.

Why did the original FTP specification RFC 959 decide to create both a control port and a data port?

Would there be any reason to do this in a similar custom protocol?

It seems to me that this could have been easily specified on a single port.

Given all the problems with firewalls and NATS with FTP, it seems that a single port would have been much better.

For a general protocol implementation, the only reason I could think that you would want to do this is so that you can serve the files from a different host than the commands are going to.

like image 909
Brian R. Bondy Avatar asked Mar 09 '09 15:03

Brian R. Bondy


People also ask

Which protocol uses 2 ports?

FTP also is odd in that it uses two ports to accomplish its task. It typically uses port 20 for data transfer and port 21 to listen to commands. However, having data transferred over port 20 is not always the case, as it can also be a different port as well.

What is the need of two ports in FTP protocol?

Multiple Ports, Multiple Modes. Unlike most protocols used on the Internet, FTP requires multiple network ports to work properly. When an FTP client application initiates a connection to an FTP server, it opens port 21 on the server — known as the command port. This port is used to issue all commands to the server.

What is the purpose of protocol ports?

Ports are numbered and used as global standards to identify specific processes or types of network services. Much like before shipping something to a foreign country, you'd agree where you'd be shipping out of and where you'd have it arriving, TCP ports allow for standardized communication between devices.

What are ports 21 and 22 used for?

Some of the most commonly used ports, along with their associated networking protocol, are: Ports 20 and 21: File Transfer Protocol (FTP). FTP is for transferring files between a client and a server. Port 22: Secure Shell (SSH).


1 Answers

The initial rationale behind this was so that you could:

  • Continue sending and receiving control instruction on the control connection while you are transfering data.
  • Have more than one data connection active at the same time.
  • The server decides when it's ready to send you data.

True, they could have achieved the same result by specifying a complicated multiplexing protocol integrated to the FTP protocol, but since at that time NAT was a non issue, they chose to use what already existed, TCP ports.

Here is an example:

Alice wants two files from Bob. Alice connects to Bob port 21 and asks for the files. Bob open connections to Alice port 20 when it's ready and send the files there. Meanwhile, Charles needs a file on Alice's server. Charles connects to 21 on Alice and asks for the file. Alice connects to port 20 on Charles when ready, and sends the files.

As you can see, port 21 is for client connecting to servers and port 20 is for servers connecting to clients, but those clients could still serve files on 21.

Both ports serve a totally different purpose, and again for sake of simplicity, they chose to use two different ports instead of implementing a negotiation protocol.

like image 171
Coincoin Avatar answered Oct 04 '22 04:10

Coincoin