FTP Server in Java

by Peter Sorotokin

Current version is 0.6 (posted January 21, 2000). It contains several small patches, mostly sent by other people. I would like to thank them again.

Note: this code is Java 1.1. It might run with some minor modifications under 1.0, but I never considered this possibility in my development. This code is an application, not an applet. Applets generally cannot be servers.

You can either load pre-compiled (by Sun's JDK 1.2 java compiler) jar file from here or (more useful) download complete source code from here. Older version is here. You can use, modify and distribute this program as long as copyright notice in the source code is retained. Beware that any kind of server running on your machine can be dangerous in terms of security. This code is not adequately tested. Code is provided "AS IS", use at your own risk.

INSTALLATION: Windows 95: Download pre-compiled jar file into some directory, say "c:\ftpd". Create a batch file "c:\ftpd\ftpd.bat" with the following line:

c:\jdk1.2\bin\java.exe -classpath c:\ftpd;c:\ftpd\ftpd.jar kmy.net.ftpd.FTPDaemon 21
You also might want to create a shortcut to this batch file on your desktop. Also you need to replace "c:\jdk1.2" with whatever you jdk path is. If you are using JRE, than you have to run jre.exe, not java.exe. Run the batch file. There should not be any messages at this point. From another window type in:
ftp your-machine-name
You should see the following line appear on the first window:
FTP<220 bear FTP server (Version kmy-0.6) ready.
Now you can log in using username "kmy" and password "test12". Home directory for this user is "\home\kmy", so you might want to create it. You also can log in using username ftp or anonymous, then the server will try to hold you within the limits of "\ftp" and its subdirectories.

UNIX folks: I rely on you being smart enough to deduce UNIX installation from Windows one. Note that you have to use different port number (don't run this code as root, please!), or use some sort of port redirector. So change 21 to, say, 2121 and then use ftp command like this:

ftp your-machine-name 2121
Beware that non-default port number generally will not work through the firewall!

Someone told me that it works on Mac as well (I am sorry that I do not know your name, I did not save that message).

CONFIGURATION: Extract this file from a jar (you should be in c:\ftpd):

jar xvf ftpd.jar kmy\net\ftpd\FTPD.conf
You can edit it to add/remove users. Initially this file looks like this:
That means we have two users. The first one has login name "kmy", password "test12", he is not limited to his home directory and subfolders and his home directory is "/home/kmy" (use forward slash here). User "ftp" also has a "virtual root" set up; that means that this user will see /ftp/path as /path.

SOURCE CODE: This ftp server is ment to be subclassed and modified to work inside some bigger system. (That is how I am going to use it myself, at least). You can browse javadoc-generated documentation here.

BUGS: For some reason I cannot list root directory on Windows. This may be JDK bug. Also I never use port 20 to bind data transfer connection. And the file pattern expansion can give unexpected results. For example, command "dir /home/km?" will generally give you information on a directory /home/kmy, not its content. Patterns should work correctly with mget, though. Bugs, fixes, questions and comments: sorotokin@yahoo.com. Note: I do not have enough time to maintain this code, do not rely on me fixing something. This project is my personal and is not supported by my employer. 

Want a maze? Check out my Maze Page!   Enjoy!