Click here to Skip to main content
Licence 
First Posted 10 Mar 2006
Views 58,617
Bookmarked 23 times

WSTD-Ftp, A neat FTP server

By | 10 Mar 2006 | Article
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

About the Author

Moagiz

Web Developer

Israel Israel

Member

An Israeli C++ programmer.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalvery slow PinmemberMember #16067716:29 22 Feb '07  
QuestionI want to know how the trasfer rate limit implement in the application? PinmemberJim Cai20:34 23 Oct '06  
AnswerRe: I want to know how the trasfer rate limit implement in the application? PinmemberMoagiz6:05 16 Dec '06  
GeneralA question. Pinmemberforeverfenjin13:46 2 Apr '06  
GeneralRe: A question. PinmemberMoagiz3:51 3 Apr '06  
GeneralRe: A question. Pinmemberforeverfenjin6:46 3 Apr '06  
GeneralRe: A question. PinmemberMoagiz20:24 3 Apr '06  
GeneralRe: A question. PinmemberMoagiz0:29 4 Apr '06  
GeneralRe: A question. Pinmemberforeverfenjin1:23 4 Apr '06  
GeneralRe: A question. Pinmemberforeverfenjin2:45 4 Apr '06  
I find the bug.
 
char *utils_MonthName(int m)
{
static char *months[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
 
if (m < 0 || m >= 12)
return NULL;
 
return months[m];
}
m>=12 change to m>12
return months[m] change to months[m-1]
 
why a empty directory cound't be shown?
GeneralRe: A question. PinmemberMoagiz7:31 4 Apr '06  
GeneralRe: A question. Pinmemberforeverfenjin4:44 5 Apr '06  
GeneralCrash PinmemberBrad Bruce14:21 25 Mar '06  
GeneralRe: Crash PinmemberMoagiz19:42 25 Mar '06  
GeneralRe: Crash PinmemberBrad Bruce2:08 26 Mar '06  
GeneralRe: Crash PinmemberMoagiz4:12 26 Mar '06  
GeneralWelcomeFile field PinmemberPiccinano0:50 18 Mar '06  
GeneralRe: WelcomeFile field PinmemberMoagiz1:31 18 Mar '06  
GeneralRe: WelcomeFile field PinmemberMoagiz5:43 18 Mar '06  
GeneralRe: WelcomeFile field PinmemberPiccinano22:51 18 Mar '06  
GeneralSmall bug in the String class Pinmembernkul19:28 14 Mar '06  
GeneralRe: Small bug in the String class PinmemberMoagiz19:44 14 Mar '06  
Generalmissing file attribute in v6 Pinmemberwhoisthis6:13 14 Mar '06  
GeneralRe: missing file attribute in v6 PinmemberMoagiz6:27 14 Mar '06  
GeneralRe: missing file attribute in v6 Pinmemberwhoisthis9:54 14 Mar '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 10 Mar 2006
Article Copyright 2006 by Moagiz
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid