FTP Server in C#


Introduction

The application is a simple implementation of FTP Protocol RFC 959.

Technology Used

System.Net.Socket,Multithreading.

FTP  : The objectives of FTP are 1) to promote sharing of files (computer programs and/or data), 2) to encourage indirect or implicit (via programs) use of remote computers, 3) to shield a user from variations in file storage systems among hosts, and 4) to transfer data reliably and efficiently. FTP, though usable directly by a user at a terminal, is designed mainly for use by programs.

THE FTP MODEL

With the above definitions in mind, the following model (shown in  Figure 1) may be diagrammed for an FTP service.

In the model described in Figure 1, the user-protocol interpreter initiates the control connection. The control connection follows the Telnet protocol. At the initiation of the user, standard FTP commands are generated by the user-PI and transmitted to the server process via the control connection. (The user may establish a direct control connection to the server-FTP, from a TAC terminal for example, and generate standard FTP commands independently, bypassing the user-FTP process.) Standard replies are sent from the server-PI to the user-PI over the control connection in response to the commands.

The FTP commands specify the parameters for the data connection (data port, transfer mode, representation type, and structure) and the nature of file system operation (store, retrieve, append, delete, etc.). The user-DTP or its designate should "listen" on the specified data port, and the server initiate the data connection and data transfer in accordance with the specified parameters. It should be noted that the data port need not be in the same host that initiates the FTP commands via the control connection, but the user or the user-FTP process must ensure a "listen" on the specified data port. It ought to also be noted that the data connection may be used for simultaneous sending and receiving. In another situation a user might wish to transfer files between two hosts, neither of which is a local host. The user sets up control connections to the two servers and then arranges for a data connection between them. In this manner, control information is passed to the user-PI but data is transferred between the server data transfer processes. Following is a model of this server-server interaction.



The protocol requires that the control connections be open while data transfer is in progress. It is the responsibility of the user to request the closing of the control connections when finished using the FTP service, while it is the server who takes the action. The server may abort data transfer if the control connections are closed without command.

About the sample

Server is a Win Form application which acts as a Console window for the application. As this application is a multithreaded application it can handle lot many clients. Their is session window from where you can end any of the current session of the client . At present in this application you will be just see "System.Thread " and you can select a item and say disconnect which will disconnect the Client from the Server. Present application uses C: as the directory and I have not provided any setup screen, this means there is no user and no password too, any one can log to this server with any user name and any password. You can very easily make this changes in the code and can use this.

Good luck and Enjoy C#

Up Next
    Ebook Download
    View all
    Learn
    View all