In this two part series about FTP we are going to look at what an FTP server is and what it is used for. The first part will cover the theory and the second part will put all the theory into practice; it's where we will actually implement an FTP server. I'm doing the theory first to give you a bit of background about the FTP protocol. This will make it easy for you to understand the purpose of each command in the protocol as well as how to implement them in the next article.
FTP Server: The Theory - Access Control Commands (Page 4 of 5 )
The FTP commands are divided into sections, one of which is called access control commands. These commands include:
USER <SP> <username> <CRLF>
PASS <SP> <password> <CRLF>
ACCT <SP> <account-information> <CRLF>
CWD <SP> <pathname> <CRLF>
CDUP <CRLF>
SMNT <SP> <pathname> <CRLF>
QUIT <CRLF>
These commands are important because they allow you to access, manipulate and control a file system. But for the purposes of the application that we will create in the next article, we only need to explain the USER, PASS and QUIT commands.
The USER command is used to identify the user that wants to access a file system. It has the following syntax:
USER Ausername
This command will normally be the first command transmitted by the user after the control connections are made.
The PASS command takes the user's password, which should be entered immediately after the user command has been entered. It has the following syntax:
PASS Apassword
These authentication methods are required by some servers. Others will allow anonymous access and a few others will not need any kind of authentication. Needless to say, it is always best to have some kind of authentication, for security reasons. How you implement these commands is completely up to you as the protocol does not specify any method for doing this. A good way would be to hold the user names and passwords in a database and verify them when a user logs in.
The QUIT command terminates or logs out the user and closes the control connection if no file transfer is in progress. If there is a file transfer in progress when the user tries to log out (QUIT), the protocol describes what happens:
"If file transfer is in progress, the connection will remain open for result response and the server will then close it. If the user-process is transferring files for several USERs but does not wish to close and then reopen connections for each, then the REIN command should be used instead of QUIT. An unexpected close on the control connection will cause the server to take the effective action of an abort (ABOR) and a logout (QUIT)."