Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quick FTP server

Tags:

ruby

rubygems

ftp

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.

like image 682
alf Avatar asked May 04 '12 23:05

alf


1 Answers

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

like image 79
Wayne Conrad Avatar answered Sep 20 '22 03:09

Wayne Conrad