How to Setup a Home FTP Server – Part1

The growing interest in file sharing leads me to address the subject of a home FTP server.
Currently, with all the restrictions that file sharing is having, with RIAA lawsuits, MPAA lawsuits and internet service providers  canceling accounts and blocking access, set up a home FTP server to exchange files with friends is almost a necessity. The advantage? It is a connection not promiscuous and  has a high degree of confidence, since only known peers are connected. But first a little theory.

FTP (File Transfer Protocol)
File Transfer Protocol (FTP) is a standard network protocol used to copy a file from one host to another through a network based on TCP / IP, such as the Internet. FTP is built on a client-server connections and uses separate ports to control  data between the client and server. The control connection is on port 21 and the data connection is on port 20, both on the server side. On the client side things change a little.
FTP users can authenticate via username and password, but can also log in anonymously, if the server is configured to allow this.

FTP passive and active
There are two modes of FTP: Active and Passive. The explanation on how they work is as follows.

Active FTP
In active mode FTP the client connects from a random unprivileged port (N > 1023) to the FTP server’s command port, port 21. Then, the client starts listening to port N+1 and sends the FTP command PORT N+1 to the FTP server. The server will then connect back to the client’s specified data port from its local data port, which is port 20.
From the server-side firewall’s standpoint, to support active mode FTP the following communication channels need to be opened:

  • FTP server’s port 21 from anywhere (Client initiates connection)
  • FTP server’s port 21 to ports > 1023 (Server responds to client’s control port)
  • FTP server’s port 20 to ports > 1023 (Server initiates data connection to client’s data port)
  • FTP server’s port 20 from ports > 1023 (Client sends ACKs to server’s data port)

When drawn out, the connection appears as follows:

Passive FTP
In passive mode FTP the client initiates both connections to the server, solving the problem of firewalls filtering the incoming data port connection to the client from the server. When opening an FTP connection, the client opens two random unprivileged ports locally (N > 1023 and N+1). The first port contacts the server on port 21, but instead of then issuing a PORT command and allowing the server to connect back to its data port, the client will issue the PASV command. The result of this is that the server then opens a random unprivileged port (P > 1023) and sends the PORT P command back to the client. The client then initiates the connection from port N+1 to port P on the server to transfer data.
From the server-side firewall’s standpoint, to support passive mode FTP the following communication channels need to be opened:

  • FTP server’s port 21 from anywhere (Client initiates connection)
  • FTP server’s port 21 to ports > 1023 (Server responds to client’s control port)
  • FTP server’s ports > 1023 from anywhere (Client initiates data connection to random port specified by server)
  • FTP server’s ports > 1023 to remote ports > 1023 (Server sends ACKs (and data) to client’s data port)

When drawn, a passive mode FTP connection looks like this:

Then, in passive mode, who determines which ports are used for the data to be transferred is the server, not the client, as in active mode.

Disadvantages of Active Mode
The main problem with active mode is: Since the request of ports is made on the client side, it becomes problematic for the firewall / NAT / Router to handle client requests.
In passive mode, since it is the server that determines which ports it will use, it is easier to set up the whole structure of firewall / NAT / Router.

Home FTP Server – Considerations
To successfully implement a home FTP server  we need to consider what is the structure that we have.
Our server will be located on a machine behind a modem / router, in an internal LAN and communicating with the world through this modem / router.
As internet service providers block lower ports , <1024, we have to configure a NAT on the modem / router so that computers can access the external FTP control port (21) and the data ports.
The active mode is good enough for local networks, mainly behind a firewall / router, as the use of random ports will not harm the client connection.
But for connections through the Internet, you must use passive mode, which is much more configurable.
Of course, we also need an FTP server program, so we can perform the file transfer actions.
Well, after this brief introduction, the theory of what is FTP, we will cover how to set up the server and all the settings required for its proper functioning.

Continues here

Leave a Reply

Your email address will not be published. Required fields are marked *