-
-
Save sam/2588648 to your computer and use it in GitHub Desktop.
| require "java" | |
| jars = File.join(File.dirname(__FILE__), "*.jar") | |
| Dir[jars].each { |jar| require jar } | |
| import org.apache.ftpserver.FtpServer | |
| import org.apache.ftpserver.FtpServerFactory | |
| import org.apache.ftpserver.listener.ListenerFactory | |
| server_factory = FtpServerFactory.new | |
| listener_factory = ListenerFactory.new | |
| listener_factory.port = 2221 | |
| server_factory.add_listener "default", listener_factory.create_listener | |
| server = server_factory.create_server | |
| # start the server | |
| server.start |
If you look at line 129 here: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/impl/LIST.java?view=markup#L129
And line 196 here:
http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java?view=markup#L196
You start to get an idea of how you could easily bend the library to your will, allowing you to create a "Rails for FTP".
@fgrehm FYI, thought you might find this interesting. :)
Here's an example of adding/overriding the defaults with your own commands: http://mail-archives.apache.org/mod_mbox/mina-ftpserver-users/201003.mbox/%3Cf63349b31003220848n4ce950a9m1f8856ee508e6585@mail.gmail.com%3E
The list of commands you'd need to appropriately override to create a dynamic FTP server isn't exactly short (start at line 89 here: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/command/CommandFactoryFactory.java?view=markup#L89) , but most of the ones you'd have to touch probably map pretty easily to a REST-alike interface.
Also, unlike with ProFTPd, with this you could BCrypt your user database, and authenticate directly against it in your FTP server.
To try this on your own machine download the 1.0.6 release of Apache's FTP Server: http://mina.apache.org/ftpserver/downloads.html
Extract it, then copy the jar files from ./common/lib. You can copy all of them, but you only need mina_, ftplet_ ftpserver_, log4j_ and slf4j* files.
We're starting the server on port 2221 in this example because 21 is a privileged port. So this way we don't need root access just to try our example.