The purpose of this project is to develop the client and server sides of a simple ftp application.
I started this lab with a simple client and server file that connected over TCP and could exchange data freely. After that I implemented a form of a control loop for my client that uses a variable I call FTP_STATUS to act as a kinda finite state machine. I do a similar thing on the server side. Since the first thing our client should do is issue the PORT command to the server, once my client enters its main control loop, it issues that command to the server. This causes the client to thread a process I call ftpPORT, which makes the client listen on the clients original port is used to connect to the server -1. Once the server receives the PORT command it will also spawn a thread, but the server will actively connect to my client to officially open the socket that will be used for data transfer.
If the data connection has been established successfully, the client will see the message “200 Command OK” printed on their screen followed by “ftp>” signifying that the program is waiting for an input. At this point, the client can issue the following commands; “ls” which lists everything in the servers directory, “get <file-name.txt>” which will cause the server to send the client file-name.txt and save it as that name in their current directory, “put <file-name.txt>” which will cause the client to send the server file-name.txt and save it in their current directory, or finally “quit” which will cause the server to send the client “221 Goodbye.” and close the connection, causing the server to go back into the listening state on its “well-known” port number it was given as a command line argument. If all of those commands execute successfully, the user will see “200 Command OK” on their screen. And, in order to demonstrate that I gained a bit of knowledge on using threads, each of the commands the client take\ and the server responds to, are dealt with in their own thread.
When it comes to recovering from errors, the only one I have yet to recover from is when the data connection can not be opened. The server encounters an error when calling connect and sends “452 Can't open data connection.” but my client doesn’t read it in because its sitting waiting in accept( ). If given more time I would have perhaps implemented some form of timeout on the accept function before it would retry. The other aspect of my ftp program that is not totally working correctly is server
and the ABOR protocol command. My program doesn’t listen for that or cut off any data transfer if this command were to arise. However, If “get” or “put” are passed to the server with files that do not exist, the client will see the message "450 Error opening file.” printed to their screen. If the client tried to execute a command the server does not handle, it will result in a "500 Syntax Error.”. I, addition, I also use "450 Error writing file.” if the file transferred to the server can’t be written, or the tile being received from the server can’t be written.