I'm looking for a quick, configuration-less, FTP server. Something exactly like Serve or Rack_dav, but for FTP, which can publish a folder just by running a command. Is there a gem or something to do such thing?
Solution
Based on Wayne's ftpd gem, I created a quick and easy-to-use gem called Purvey.
The ftpd gem supports TLS, and comes with a file system driver. Like em-ftpd, you supply a driver, but that driver doesn't need to do much. Here's a bare-minimum FTP server that accepts any username/password, and serves files out of a temporary directory:
require 'ftpd'
require 'tmpdir'
class Driver
def initialize(temp_dir)
@temp_dir = temp_dir
end
def authenticate(user, password)
true
end
def file_system(user)
Ftpd::DiskFileSystem.new(@temp_dir)
end
end
Dir.mktmpdir do |temp_dir|
driver = Driver.new(temp_dir)
server = Ftpd::FtpServer.new(driver)
server.start
puts "Server listening on port #{server.bound_port}"
gets
end
NOTE: This example allows an FTP client to upload, delete, rename, etc.
To enable TLS:
include Ftpd::InsecureCertificate
...
server.certfile_path = insecure_certfile_path
server.tls = :explicit
server.start
Disclosure: I am ftpd's author and current maintainer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With