Skip to content

Instantly share code, notes, and snippets.

@sam
Created May 3, 2012 19:37
Show Gist options
  • Select an option

  • Save sam/2588648 to your computer and use it in GitHub Desktop.

Select an option

Save sam/2588648 to your computer and use it in GitHub Desktop.
Example for org.apache.ftpserver on JRuby
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
@sam
Copy link
Author

sam commented May 3, 2012

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.

@sam
Copy link
Author

sam commented May 3, 2012

@sam
Copy link
Author

sam commented May 3, 2012

@fgrehm FYI, thought you might find this interesting. :)

@sam
Copy link
Author

sam commented May 4, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment