A C# FTP Server | CodeGuru

A C# FTP Server

Introduction 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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Jun 16, 2004
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Introduction

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…

Advertisement

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.

Limitations

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.

References

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

Conclusion

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.