A C# FTP Server


This is a fully functional FTP server that works with Internet Explorer and Netscape. I think the code itself is self explanatory. Eveything starts with a main form (MainForm.cs). Each user’s starting directories are set up in UserForm.cs. There are some points of note:

Point 1: Adding Users

You must add users first, before using the FTP server.

The buttons in the user’s dialog operate only if a user is selected.

Point 2: Functionality

This server will work with most clients, including Internet Explorer and Netscape Navigator. Each use a different method of transferring data (see below for a link to the FTP specification that gives more information).

Point 3: The FTP Server Is in an Assembly

Now, why do this? Surely you won’t ever want to use an FTP server elsewhere? Nope! In actual fact, I’ve come across several usages of the FTP protocol other than just file transfer. Which brings me to Point 4…

Point 4: The Interface to the File System Is Replaceable

All file system accesses (for example, file open/write, list directory files, and so forth) go through a set of interfaces (see Assembly.Ftp.FileSystem.IFile, and so on).

The class factory for the file system object—the object that creates the file system object (Assembly.Ftp.FileSystem.IFileSystemClassFactory)—is passed in to the FTP server on creation. You can replace this with whatever you want (derived from IFileSystemClassFactory) and create classes that derive from IFileSystem, IFile, and IFileInfo to get the FTP server to do what you want.

Now, why do this? Well, this gives a huge amount of flexibility of use for this server. You could, for instance, change the FTP server so that it addresses the Registry and not the file system. You could even get it to address a database, or could use it as an external interface to access data in a large application.


There is one limitation of the system:

  1. “ABOR” doesn’t work (abortion from downloading/uploading files). Basically, the send and receive are done on the same thread as the commands instead of a seperate one. There’s no reason why this can’t be changed.


The vast majority of the information for building this site came from http://cr.yp.to/ftp.html, which is a really excellent source.


The FTP server is pretty much self explanatory, really. I don’t think I need to add anything else here. And, how did I find C#? Well, considering I had an operational FTP server inside of two days, without knowing what the protocol was when I started, I’m really impressed. It’s taken me a while to realise how good C# is (especially when taken with C++ .NET assemblies), but I’m a big fan now.

I hope you find this code useful.

More by Author

Must Read