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.
-
#nat_ip ⇒ nil, String
The advertised public IP for passive mode connections.
-
#passive_ports ⇒ nil, Range
The range of ports for passive mode connections.
-
#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:
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ftpd/ftp_server.rb', line 179 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 = Release::VERSION @allow_low_data_ports = false @failed_login_delay = 0 @nat_ip = nil @passive_ports = nil 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.
22 23 24 |
# File 'lib/ftpd/ftp_server.rb', line 22 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
32 33 34 |
# File 'lib/ftpd/ftp_server.rb', line 32 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.
Set this before calling #start.
161 162 163 |
# File 'lib/ftpd/ftp_server.rb', line 161 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.
38 39 40 |
# File 'lib/ftpd/ftp_server.rb', line 38 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.
46 47 48 |
# File 'lib/ftpd/ftp_server.rb', line 46 def list_formatter @list_formatter end |
#log ⇒ Logger
The logger. Defaults to nil (no logging).
Set this before calling #start.
54 55 56 |
# File 'lib/ftpd/ftp_server.rb', line 54 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.
68 |
# File 'lib/ftpd/ftp_server.rb', line 68 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.
90 |
# File 'lib/ftpd/ftp_server.rb', line 90 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.
79 80 81 |
# File 'lib/ftpd/ftp_server.rb', line 79 def max_failed_logins @max_failed_logins end |
#nat_ip ⇒ nil, String
The advertised public IP for passive mode connections. This is the IP that the client must use to make a connection back to the server. If nil, the IP of the bound interface is used. When the FTP server is behind a firewall, set this to firewall’s public IP and add the appropriate rule to the firewall to forward that IP to the machine that ftpd is running on.
Set this before calling #start.
103 104 105 |
# File 'lib/ftpd/ftp_server.rb', line 103 def nat_ip @nat_ip end |
#passive_ports ⇒ nil, Range
The range of ports for passive mode connections. If nil, then a random etherial port is used. Otherwise, a random port from this range is used.
Set this before calling #start.
112 113 114 |
# File 'lib/ftpd/ftp_server.rb', line 112 def passive_ports @passive_ports 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.
122 123 124 |
# File 'lib/ftpd/ftp_server.rb', line 122 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.
131 132 133 |
# File 'lib/ftpd/ftp_server.rb', line 131 def server_name @server_name end |
#server_version ⇒ String
The server’s version, sent in a STAT reply. Defaults to Release::VERSION.
Set this before calling #start.
140 141 142 |
# File 'lib/ftpd/ftp_server.rb', line 140 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.
151 152 153 |
# File 'lib/ftpd/ftp_server.rb', line 151 def session_timeout @session_timeout end |
Instance Method Details
#on_exception(&block) ⇒ Object
Defines the exception_handler.
165 166 167 |
# File 'lib/ftpd/ftp_server.rb', line 165 def on_exception(&block) self.exception_handler = block end |