• Stars
    star
    100
  • Rank 340,829 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 15 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight FTP server framework built on the EventMachine

em-ftpd

Maintainer Required

I'm no longer actively maintaining this library. If anyone would like to take over maintainership, please let me know via github issue #6.

Overview

A mini-FTP server framework built on top of the EventMacine gem. By providing a simple driver class that responds to a handful of methods you can have a complete FTP server.

The library is extracted from real world situations where an FTP interface was required to sit in front of a non-filesystem persistence layer.

Some sample use cases include persisting data to:

  • an Amazon S3 bucket
  • a relational database
  • redis
  • memory

The examples directory contains a demonstration of in memory persistence.

Installation

gem install em-ftpd

Usage

To boot an FTP server you will need to provide a driver that speaks to your persistence layer.

Create a config.rb file that loads the driver and then configures the server

require 'my_fancy_driver'

driver    MyFancyDriver
user      'ftp'
group     'ftp'

Run your server like so:

em-ftpd config.rb

Config File

Valid options for the config file are:

  • user [name of system user to run the process as]
  • group [name of group to run the process as]
  • daemonise [true/false]
  • name [a string to include in the process description]
  • pid_file [a path to save the pid to. Useful in conjunction with daemonise]
  • port [the TCP port to bind to. Defaults to 21]
  • driver [the class that connects to the persistance layer]
  • driver_args [any arguments that need to be passed to the driver constructor]

The Driver Contract

The driver MUST have the following methods. Each method MUST accept a block and yield the appropriate value:

authenticate(user, pass, &block)
- boolean indicating if the provided details are valid

bytes(path, &block)
- an integer with the number of bytes in the file or nil if the file
  doesn't exist

change_dir(path, &block)
- a boolen indicating if the current user is permitted to change to the
  requested path

dir_contents(path, &block)
- an array of the contents of the requested path or nil if the dir
  doesn't exist. Each entry in the array should be
  EM::FTPD::DirectoryItem-ish

delete_dir(path, &block)
- a boolean indicating if the directory was successfully deleted

delete_file(path, &block)
- a boolean indicating if path was successfully deleted

rename(from_path, to_path, &block)
- a boolean indicating if from_path was successfully renamed to to_path

make_dir(path, &block)
- a boolean indicating if path was successfully created as a new directory

get_file(path, &block)
- nil if the user isn't permitted to access that path
- an IOish (File, StringIO, IO, etc) object with data to send back to the
  client
- a string with the file data to send to the client
- an array of strings to join with the standard FTP line break and send to
  the client

The driver MUST have one of the following methods. Each method MUST accept a block and yield the appropriate value:

put_file(path, tmp_file_path, &block)
- an integer indicating the number of bytes received or False if there
  was an error

put_file_streamed(path, datasocket, &block)
- an integer indicating the number of bytes received or False if there
  was an error

Authors

James Healy [email protected] http://www.yob.id.au John Nunemaker [email protected] Elijah Miller [email protected]

Warning

FTP is an incredibly insecure protocol. Be careful about forcing users to authenticate with a username or password that are important.

License

This library is distributed under the terms of the MIT License. See the included file for more detail.

Contributing

All suggestions and patches welcome, preferably via a git repository I can pull from. If this library proves useful to you, please let me know.

Further Reading

There are a range of RFCs that together specify the FTP protocol. In chronological order, the more useful ones are:

For an english summary that's somewhat more legible than the RFCs, and provides some commentary on what features are actually useful or relevant 24 years after RFC959 was published:

For a history lesson, check out Appendix III of RCF959. It lists the preceding (obsolete) RFC documents that relate to file transfers, including the ye old RFC114 from 1971, "A File Transfer Protocol"

For more information on EventMacine, a library that (among other things) simplifies writing applications that use sockets, check out their website.

More Repositories

1

pdf-reader

The PDF::Reader library implements a PDF parser conforming as much as possible to the PDF specification from Adobe.
Ruby
1,731
star
2

graval

An experimental go FTP server framework
Go
79
star
3

pdf-preflight

Check PDF files conform to various standards
Ruby
76
star
4

db2fog

store your rails database backups in the cloud
Ruby
69
star
5

pdfreader

An experimental PDF reader for go
Go
56
star
6

puma-plugin-statsd

A puma plugin that sends key metrics to statsd
Ruby
47
star
7

onix

A convenient mapping between ruby objects and the ONIX XML specification
Ruby
39
star
8

prawn-forms

A prawn extension library for adding interactive forms
Ruby
32
star
9

pdf-wrapper

A unicode aware PDF writing library that uses the ruby bindings to various c libraries ( like cairo, pango, poppler and rsvg ) to do the heavy lifting.
Ruby
22
star
10

upc

Small library for recognising and validating UPC numbers
Ruby
21
star
11

abn

Small library for validating Australian Business Numbers
Ruby
15
star
12

ean13

A small library for generating and validating EAN-13's
Ruby
15
star
13

s3ftp

A mini FTP server that persists all data to S3
Ruby
15
star
14

cargowise

A wrapper for the Cargowise SOAP API, for tracking freight
Ruby
15
star
15

prawn-js

A small extension to prawn that simplifies embedding JavaScript in your PDF files
Ruby
13
star
16

gem-lint

Check rubygem files for common mistakes and errors
Ruby
12
star
17

pgredis

Redis in front, postgresql out back
Go
11
star
18

onix-dtd

A debian package containing various ONIX DTDs
7
star
19

buildkite-trace

A mini HTTP server that converts buildkite webhooks into datadog APM traces
Ruby
6
star
20

prawn-rails-xaccelredirect

Sample rails app that exhibits using Prawn and Ngnix's X-Accel-Redirect feature to generate and stream PDFs
Ruby
5
star
21

ean13.net

A .net library for recognising and validating EAN codes.
C#
5
star
22

strip_control_chars

a small ActiveRecord plugin that strips ASCII control chars from string attributes before saving
Ruby
5
star
23

istc

Small library for recognising and validating ISTC numbers
Ruby
4
star
24

cuecat

a small ruby library for decoding cuecat codes
Ruby
4
star
25

csv2onix

rails app for converting CSV files to ONIX files
Ruby
4
star
26

bisac

small library for parsing and generating BISAC files
Ruby
4
star
27

debian-rubinius

Ruby
4
star
28

lita-gsuite

Monitor activity and data in a gsuite account
Ruby
3
star
29

gbip

wrapper for the globalbooksinprint.com commercial API
Ruby
3
star
30

isbn10

a (very) small library for working with ISBN10 codes
Ruby
3
star
31

titlepage

Wrapper for the SOAP API at titlepage.com.au
Ruby
3
star
32

san

a (very) small library for working with Standard Address Numbers
Ruby
3
star
33

isni

a (very) small library for working with ISNI and ORCID
Ruby
3
star
34

activemdb

fork of http://rubyforge.org/projects/activemdb/
Ruby
3
star
35

dumb_quotes

a small ActiveRecord plugin that converts 'smart quotes' to their ASCII equivalents
Ruby
3
star
36

home-data

data collection from home
Go
3
star
37

wedded-wives

mini wedding registry site for my sister
Ruby
3
star
38

symmetric_file

Encrypt basic files in ruby using symmetric encryption
Ruby
2
star
39

morecane

Extra checks for cane
Ruby
2
star
40

gcp-tree

Ruby
2
star
41

lint_report

run gem_lint across all public rubygems
Ruby
2
star
42

replace_entities

An active record plugin for replacing HTML entities with UTF-8 characters
Ruby
2
star
43

amber_electric

a ruby API client for Amber Electric (https://amberelectric.com.au)
Ruby
2
star
44

editx

Library that simplifies working eith EDItX XML files in ruby
Ruby
2
star
45

rba-terminal

A debian package that simplifies setting up a RDP thin terminal
2
star
46

rvista

Basic library for reading and generating Vista HDS ecommerce files in Ruby
Ruby
2
star
47

share-rb-demo

A sinatra app that demos share.rb, a ruby port of sharejs
Ruby
2
star
48

ean8

a (very) small library for working with EAN8 codes
Ruby
2
star
49

pacstream

Small library to keeping communication with the pacstream server nice and simple
Ruby
2
star
50

subjct

A sinatra app for crowdsourcing links between BIC and BISAC subjects
Ruby
2
star
51

jswin

Attempting to work out a better way of building complex things with Javascript using Coffee, Jasmine, cakefiles & other fun stuff.
Ruby
2
star
52

raval

An experimental ruby FTP server built on celluloid
Ruby
2
star
53

lita-timing

Utilities for time related tasks in lita
Ruby
1
star
54

useragent_supports

Check if a user agent string supports a feature
Ruby
1
star