Click here to Skip to main content
15,880,469 members
Articles / Desktop Programming / MFC
Article

WSTD-Ftp, A neat FTP server

Rate me:
Please Sign up or sign in to vote.
3.45/5 (14 votes)
10 Mar 20063 min read 90.2K   1.3K   25   35
An article about a neat FTP server I've written, called WSTD-Ftp.

Introduction

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... :$

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Israel Israel
An Israeli C++ programmer.

Comments and Discussions

 
Generalvery slow Pin
swliu_sysu22-Feb-07 6:29
swliu_sysu22-Feb-07 6:29 
QuestionI want to know how the trasfer rate limit implement in the application? Pin
Jim Cai23-Oct-06 20:34
Jim Cai23-Oct-06 20:34 
AnswerRe: I want to know how the trasfer rate limit implement in the application? Pin
Moagiz16-Dec-06 6:05
Moagiz16-Dec-06 6:05 
GeneralA question. Pin
foreverfenjin2-Apr-06 13:46
foreverfenjin2-Apr-06 13:46 
GeneralRe: A question. Pin
Moagiz3-Apr-06 3:51
Moagiz3-Apr-06 3:51 
GeneralRe: A question. Pin
foreverfenjin3-Apr-06 6:46
foreverfenjin3-Apr-06 6:46 
GeneralRe: A question. Pin
Moagiz3-Apr-06 20:24
Moagiz3-Apr-06 20:24 
GeneralRe: A question. Pin
Moagiz4-Apr-06 0:29
Moagiz4-Apr-06 0:29 
GeneralRe: A question. Pin
foreverfenjin4-Apr-06 1:23
foreverfenjin4-Apr-06 1:23 
GeneralRe: A question. Pin
foreverfenjin4-Apr-06 2:45
foreverfenjin4-Apr-06 2:45 
GeneralRe: A question. Pin
Moagiz4-Apr-06 7:31
Moagiz4-Apr-06 7:31 
GeneralRe: A question. Pin
foreverfenjin5-Apr-06 4:44
foreverfenjin5-Apr-06 4:44 
GeneralCrash Pin
Brad Bruce25-Mar-06 14:21
Brad Bruce25-Mar-06 14:21 
GeneralRe: Crash Pin
Moagiz25-Mar-06 19:42
Moagiz25-Mar-06 19:42 
GeneralRe: Crash Pin
Brad Bruce26-Mar-06 2:08
Brad Bruce26-Mar-06 2:08 
GeneralRe: Crash Pin
Moagiz26-Mar-06 4:12
Moagiz26-Mar-06 4:12 
GeneralWelcomeFile field Pin
Piccinano18-Mar-06 0:50
Piccinano18-Mar-06 0:50 
GeneralRe: WelcomeFile field Pin
Moagiz18-Mar-06 1:31
Moagiz18-Mar-06 1:31 
GeneralRe: WelcomeFile field Pin
Moagiz18-Mar-06 5:43
Moagiz18-Mar-06 5:43 
GeneralRe: WelcomeFile field Pin
Piccinano18-Mar-06 22:51
Piccinano18-Mar-06 22:51 
GeneralSmall bug in the String class Pin
nkul14-Mar-06 19:28
nkul14-Mar-06 19:28 
GeneralRe: Small bug in the String class Pin
Moagiz14-Mar-06 19:44
Moagiz14-Mar-06 19:44 
Generalmissing file attribute in v6 Pin
whoisthis14-Mar-06 6:13
whoisthis14-Mar-06 6:13 
GeneralRe: missing file attribute in v6 Pin
Moagiz14-Mar-06 6:27
Moagiz14-Mar-06 6:27 
I have it in winbase.h

"#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)"

Hope this helps...
GeneralRe: missing file attribute in v6 Pin
whoisthis14-Mar-06 9:54
whoisthis14-Mar-06 9:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.