As far as I know, there's a lack of free Windows FTP servers available for download on the Internet. This seemed to me a bit weird since I think that writing a decent FTP server is not such hard a task. To prove my point, I've written this FTP server which implements all the necessary abilities I could think of. It supports multiple users, per-directory permissions, data transfer rate limiting, and it also prints out a nice log file! The only downside is that due to severe laziness, I've never written a Settings dialog for the application, which means that settings should be modified manually using regedit (but it's a great deal of fun, believe me! :-).
Also, please use WSTD-Ftp without any warranty, I guess that there might be some bugs inside the code (which I would like to hear about) that could make this server vulnerable!
Using the code
First, let's start with the tricky part, the configuration. When you first run the server, it would load the default configuration into the registry (HKCU\Software\WSTD\WSTDFtp). This is the server configuration (which includes things like server port etc.), the default configuration is OK. What you need to do is, configure a user or two, so people would be able to log on to your server. Use the "users.reg" file from the ZIP, it would load into the registry the configurations of two users: Anonymous and Admin. They both require the existence of the following tree on your hard drive:
C:\ftproot (home directory)
C:\ftproot\pub (where Anonymous can only read files)
C:\ftproot\incoming (where Anonymous can only write files)
C:\ftproot\junk (where Anonymous can do anything)
Admin can do anything anywhere (under C:\ftproot). Anonymous requires no password and has a limit of 5 Kb per second for transfers. Admin's password is "12345" and its data transfer rate is unlimited.
Use regedit and take a look at HKCU\Software\WSTD\WSTDFtp, you'd figure out in a minute how it's all done.
Now for the code structure, it is pretty much straightforward. I tried to use as many classes as possible to make it all nice and clear.
The code includes a
Path class which knows how to do important stuff like combining paths and canonicalizing paths. From the moment a user logs on, all file system operations are done by the
FtpFS class. It opens files, directories for listing, and more using the logical FTP paths (where "/" means the home directory) and while validating directory permissions.
A directory's permissions are defined to be the permissions of the closest ancestor directory for which permissions were manually declared. So, for instance, if we disallow write inside "pub" but we don't declare permissions for "pub/sub" then writing is disallowed in "pub/sub" as well. If permissions aren't declared for a directory and also for none of its ancestor directories, then the default permissions are used.
All actual FTP commands handling is done in ftpclient_cmds.cpp, each command has a function of its own.
Well that's about it, it might sound a bit frightening but the code is honestly simple: just start in main.cpp and follow the code...
Points of Interest
Writing FTP servers is not that difficult and so there should be many free Windows FTP servers available for download on the Internet!
P.S.: This is my first post on CodeProject, so please be easy on me... :$