Introduction to FTP

A client connects to a server and then sends commands to the server. Each command receives an answer from the server with either a success or failure.

For example, the client will send the PWD command to the server:

=> PWD\r\n
<= 257 "/"\r\n

Here, the server answered 257 (which literally means pathname created) and then gave the current working directory the client is in (which is "/", in this case).

As you can see, every command ended with "". This is another standard in FTP—every command has to end with "". In case you don't know, "" stands for carriage return and "" stands for the backline.

Another thing to note—the answer from the server always contains a string before the "". Consider the following example:

=> NOOP\r\n
<= 250 Doing nothing\r\n

If the client's command doesn't require a precise output (except for the returned code), it's all up to the server. It's generally just a small sentence giving more information about what the server did (or what failed). On another server, the NOOP command could have given the following:

=> NOOP\r\n
<= 250 42 is life\r\n

Lastly, FTP works with two channels:

A funny thing about this second channel is that it's up to the client to decide whether the server connects to the client or vice versa. But in almost every case, the client asks the server to connect to him for a second time, and the server picks a port and they're good to go.

We can now say that we're done with a quick introduction to FTP. If it still doesn't seem perfectly clear at this point, no need to worry: it'll become more obvious as we go through the implementation of the server.

So, let's start with a synchronous server implementation.