Class: Ftpd::FtpServer

Inherits:
TlsServer show all
Extended by:
Forwardable
Defined in:
lib/ftpd/ftp_server.rb

Constant Summary collapse

DEFAULT_SERVER_NAME =
'wconrad/ftpd'
DEFAULT_SESSION_TIMEOUT =

seconds

300

Instance Attribute Summary collapse

Attributes inherited from TlsServer

#certfile_path, #tls

Attributes inherited from Server

#interface, #port

Instance Method Summary collapse

Methods inherited from Server

#bound_port, #join, #start, #stop

Constructor Details

#initialize(driver) ⇒ FtpServer

Create a new FTP server. The server won’t start until the #start method is called.

The driver should expose these public methods:

Parameters:

  • driver

    A driver for the server’s dynamic behavior such as authentication and file system access.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/ftpd/ftp_server.rb', line 154

def initialize(driver)
  super()
  @driver = driver
  @response_delay = 0
  @list_formatter = ListFormat::Ls
  @auth_level = AUTH_PASSWORD
  @session_timeout = 300
  @server_name = DEFAULT_SERVER_NAME
  @server_version = read_version_file
  @allow_low_data_ports = false
  @failed_login_delay = 0
  self.log = nil
  @connection_tracker = ConnectionTracker.new
  @connection_throttle = ConnectionThrottle.new(@connection_tracker)
end

Instance Attribute Details

#allow_low_data_portsBoolean

If true, allow the PORT command to specify privileged data ports (those below 1024). Defaults to false. Setting this to true makes it easier for an attacker to use the server to attack another server. See RFC 2577 section 3.

Set this before calling #start.

Returns:

  • (Boolean)


20
21
22
# File 'lib/ftpd/ftp_server.rb', line 20

def allow_low_data_ports
  @allow_low_data_ports
end

#auth_levelInteger

The authentication level. One of:

  • Ftpd::AUTH_USER

  • Ftpd::AUTH_PASSWORD (default)

  • Ftpd::AUTH_ACCOUNT

Returns:

  • (Integer)

    The authentication level



30
31
32
# File 'lib/ftpd/ftp_server.rb', line 30

def auth_level
  @auth_level
end

#exception_handlerProc

The exception handler. When there is an unknown exception, server replies 451 and calls exception_handler. If nil, then it’s ignored.

Returns:

  • (Proc)


136
137
138
# File 'lib/ftpd/ftp_server.rb', line 136

def exception_handler
  @exception_handler
end

#failed_login_delayObject

The delay (in seconds) after a failed login. Defaults to 0. Setting this makes brute force password guessing less efficient for the attacker. RFC-2477 suggests a delay of 5 seconds.



36
37
38
# File 'lib/ftpd/ftp_server.rb', line 36

def 
  @failed_login_delay
end

#list_formatterclass that quacks like Ftpd::ListFormat::Ls

The class for formatting for LIST output. Defaults to ListFormat::Ls (unix “ls -l” style).

Set this before calling #start.

Returns:



44
45
46
# File 'lib/ftpd/ftp_server.rb', line 44

def list_formatter
  @list_formatter
end

#logLogger

The logger. Defaults to nil (no logging).

Set this before calling #start.

Returns:

  • (Logger)


52
53
54
# File 'lib/ftpd/ftp_server.rb', line 52

def log
  @log
end

#max_connectionsInteger

The maximum number of connections the server will allow. Defaults to ConnectionThrottle::DEFAULT_MAX_CONNECTIONS.

Set this before calling #start.

Returns:

  • (Integer)


66
# File 'lib/ftpd/ftp_server.rb', line 66

def_delegator :@connection_throttle, :'max_connections'

#max_connections_per_ipInteger

The maximum number of connections the server will allow from a given IP. Defaults to ConnectionThrottle::DEFAULT_MAX_CONNECTIONS_PER_IP.

Set this before calling #start.

Returns:

  • (Integer)


88
# File 'lib/ftpd/ftp_server.rb', line 88

def_delegator :@connection_throttle, :'max_connections_per_ip'

#max_failed_loginsInteger

The maximum number of failed login attempts before disconnecting the user. Defaults to nil (no maximum). When set, this may makes brute-force password guessing attack less efficient.

Set this before calling #start.

Returns:

  • (Integer)


77
78
79
# File 'lib/ftpd/ftp_server.rb', line 77

def max_failed_logins
  @max_failed_logins
end

#response_delayNumeric

The number of seconds to delay before replying. This is for testing, when you need to test, for example, client timeouts. Defaults to 0 (no delay).

Set this before calling #start.

Returns:

  • (Numeric)


99
100
101
# File 'lib/ftpd/ftp_server.rb', line 99

def response_delay
  @response_delay
end

#server_nameString

The server’s name, sent in a STAT reply. Defaults to DEFAULT_SERVER_NAME.

Set this before calling #start.

Returns:

  • (String)


108
109
110
# File 'lib/ftpd/ftp_server.rb', line 108

def server_name
  @server_name
end

#server_versionString

The server’s version, sent in a STAT reply. Defaults to the contents of the VERSION file.

Set this before calling #start.

Returns:

  • (String)


117
118
119
# File 'lib/ftpd/ftp_server.rb', line 117

def server_version
  @server_version
end

#session_timeoutNumeric

The session timeout. When a session is awaiting a command, if one is not received in this many seconds, the session is disconnected. Defaults to DEFAULT_SESSION_TIMEOUT. If nil, then timeout is disabled.

Set this before calling #start.

Returns:

  • (Numeric)


128
129
130
# File 'lib/ftpd/ftp_server.rb', line 128

def session_timeout
  @session_timeout
end

Instance Method Details

#on_exception(&block) ⇒ Object

Defines the exception_handler.



140
141
142
# File 'lib/ftpd/ftp_server.rb', line 140

def on_exception(&block)
  self.exception_handler = block
end