Class: Ftpd::FtpServer
- 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
-
#allow_low_data_ports ⇒ Boolean
If true, allow the PORT command to specify privileged data ports (those below 1024).
-
#auth_level ⇒ Integer
The authentication level.
-
#exception_handler ⇒ Proc
The exception handler.
-
#failed_login_delay ⇒ Object
The delay (in seconds) after a failed login.
-
#list_formatter ⇒ class that quacks like Ftpd::ListFormat::Ls
The class for formatting for LIST output.
-
#log ⇒ Logger
The logger.
-
#max_connections ⇒ Integer
The maximum number of connections the server will allow.
-
#max_connections_per_ip ⇒ Integer
The maximum number of connections the server will allow from a given IP.
-
#max_failed_logins ⇒ Integer
The maximum number of failed login attempts before disconnecting the user.
-
#response_delay ⇒ Numeric
The number of seconds to delay before replying.
-
#server_name ⇒ String
The server’s name, sent in a STAT reply.
-
#server_version ⇒ String
The server’s version, sent in a STAT reply.
-
#session_timeout ⇒ Numeric
The session timeout.
Attributes inherited from TlsServer
Attributes inherited from Server
Instance Method Summary collapse
-
#initialize(driver) ⇒ FtpServer
constructor
Create a new FTP server.
-
#on_exception(&block) ⇒ Object
Defines the exception_handler.
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:
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_ports ⇒ Boolean
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.
20 21 22 |
# File 'lib/ftpd/ftp_server.rb', line 20 def allow_low_data_ports @allow_low_data_ports end |
#auth_level ⇒ Integer
The authentication level. One of:
-
Ftpd::AUTH_USER
-
Ftpd::AUTH_PASSWORD (default)
-
Ftpd::AUTH_ACCOUNT
30 31 32 |
# File 'lib/ftpd/ftp_server.rb', line 30 def auth_level @auth_level end |
#exception_handler ⇒ Proc
The exception handler. When there is an unknown exception, server replies 451 and calls exception_handler. If nil, then it’s ignored.
136 137 138 |
# File 'lib/ftpd/ftp_server.rb', line 136 def exception_handler @exception_handler end |
#failed_login_delay ⇒ Object
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 @failed_login_delay end |
#list_formatter ⇒ class 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.
44 45 46 |
# File 'lib/ftpd/ftp_server.rb', line 44 def list_formatter @list_formatter end |
#log ⇒ Logger
The logger. Defaults to nil (no logging).
Set this before calling #start.
52 53 54 |
# File 'lib/ftpd/ftp_server.rb', line 52 def log @log end |
#max_connections ⇒ Integer
The maximum number of connections the server will allow. Defaults to ConnectionThrottle::DEFAULT_MAX_CONNECTIONS.
Set this before calling #start.
66 |
# File 'lib/ftpd/ftp_server.rb', line 66 def_delegator :@connection_throttle, :'max_connections' |
#max_connections_per_ip ⇒ Integer
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.
88 |
# File 'lib/ftpd/ftp_server.rb', line 88 def_delegator :@connection_throttle, :'max_connections_per_ip' |
#max_failed_logins ⇒ Integer
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.
77 78 79 |
# File 'lib/ftpd/ftp_server.rb', line 77 def max_failed_logins @max_failed_logins end |
#response_delay ⇒ Numeric
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.
99 100 101 |
# File 'lib/ftpd/ftp_server.rb', line 99 def response_delay @response_delay end |
#server_name ⇒ String
The server’s name, sent in a STAT reply. Defaults to DEFAULT_SERVER_NAME.
Set this before calling #start.
108 109 110 |
# File 'lib/ftpd/ftp_server.rb', line 108 def server_name @server_name end |
#server_version ⇒ String
The server’s version, sent in a STAT reply. Defaults to the contents of the VERSION file.
Set this before calling #start.
117 118 119 |
# File 'lib/ftpd/ftp_server.rb', line 117 def server_version @server_version end |
#session_timeout ⇒ Numeric
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.
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 |