Class: Ftpd::Session
- Inherits:
-
Object
- Object
- Ftpd::Session
- Defined in:
- lib/ftpd/session.rb
Constant Summary collapse
- FORMAT_TYPES =
{ 'N'=>['Non-print', true], 'T'=>['Telnet format effectors', true], 'C'=>['Carriage Control (ASA)', false], }
- DATA_TYPES =
{ 'A'=>['ASCII', true], 'E'=>['EBCDIC', false], 'I'=>['BINARY', true], 'L'=>['LOCAL', false], }
Instance Attribute Summary collapse
-
#command_sequence_checker ⇒ Object
Returns the value of attribute command_sequence_checker.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#data_channel_protection_level ⇒ Object
Returns the value of attribute data_channel_protection_level.
-
#data_hostname ⇒ Object
readonly
Returns the value of attribute data_hostname.
-
#data_port ⇒ Object
readonly
Returns the value of attribute data_port.
-
#data_server ⇒ Object
Returns the value of attribute data_server.
-
#data_server_factory ⇒ Object
Returns the value of attribute data_server_factory.
-
#data_type ⇒ Object
Returns the value of attribute data_type.
-
#epsv_all ⇒ Object
writeonly
Sets the attribute epsv_all.
-
#file_system ⇒ Object
readonly
Returns the value of attribute file_system.
-
#logged_in ⇒ Object
Returns the value of attribute logged_in.
-
#mode ⇒ Object
writeonly
Sets the attribute mode.
-
#name_prefix ⇒ Object
Returns the value of attribute name_prefix.
-
#protection_buffer_size_set ⇒ Object
Returns the value of attribute protection_buffer_size_set.
-
#socket ⇒ Object
Returns the value of attribute socket.
-
#structure ⇒ Object
writeonly
Sets the attribute structure.
Instance Method Summary collapse
- #close_data_server_socket ⇒ Object
- #command_not_needed ⇒ Object
- #ensure_logged_in ⇒ Object
- #ensure_not_epsv_all ⇒ Object
- #ensure_protocol_supported(protocol_code) ⇒ Object
- #ensure_tls_supported ⇒ Object
- #execute_command(command, argument) ⇒ Object
- #expect(command) ⇒ Object
-
#initialize(session_config, socket) ⇒ Session
constructor
A new instance of Session.
- #login(*auth_tokens) ⇒ Object
- #pwd(status_code) ⇒ Object
- #reply(s) ⇒ Object
- #run ⇒ Object
- #server_name_and_version ⇒ Object
- #set_active_mode_address(address, port) ⇒ Object
- #supported_commands ⇒ Object
- #tls_enabled? ⇒ Boolean
- #valid_command?(command) ⇒ Boolean
Methods included from ListPath
Methods included from Error
#error, #sequence_error, #syntax_error, #unimplemented_error
Constructor Details
#initialize(session_config, socket) ⇒ Session
Returns a new instance of Session.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ftpd/session.rb', line 29 def initialize(session_config, socket) @config = session_config @socket = socket if @config.tls == :implicit @socket.encrypt end @command_sequence_checker = init_command_sequence_checker @protocols = Protocols.new(@socket) @command_handlers = CommandHandlers.new @command_loop = CommandLoop.new(self) @data_server_factory = DataServerFactory.make( @socket.addr[3], config.passive_ports, ) register_commands initialize_session end |
Instance Attribute Details
#command_sequence_checker ⇒ Object
Returns the value of attribute command_sequence_checker.
9 10 11 |
# File 'lib/ftpd/session.rb', line 9 def command_sequence_checker @command_sequence_checker end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
18 19 20 |
# File 'lib/ftpd/session.rb', line 18 def config @config end |
#data_channel_protection_level ⇒ Object
Returns the value of attribute data_channel_protection_level.
10 11 12 |
# File 'lib/ftpd/session.rb', line 10 def data_channel_protection_level @data_channel_protection_level end |
#data_hostname ⇒ Object (readonly)
Returns the value of attribute data_hostname.
19 20 21 |
# File 'lib/ftpd/session.rb', line 19 def data_hostname @data_hostname end |
#data_port ⇒ Object (readonly)
Returns the value of attribute data_port.
20 21 22 |
# File 'lib/ftpd/session.rb', line 20 def data_port @data_port end |
#data_server ⇒ Object
Returns the value of attribute data_server.
11 12 13 |
# File 'lib/ftpd/session.rb', line 11 def data_server @data_server end |
#data_server_factory ⇒ Object
Returns the value of attribute data_server_factory.
12 13 14 |
# File 'lib/ftpd/session.rb', line 12 def data_server_factory @data_server_factory end |
#data_type ⇒ Object
Returns the value of attribute data_type.
13 14 15 |
# File 'lib/ftpd/session.rb', line 13 def data_type @data_type end |
#epsv_all=(value) ⇒ Object (writeonly)
Sets the attribute epsv_all
22 23 24 |
# File 'lib/ftpd/session.rb', line 22 def epsv_all=(value) @epsv_all = value end |
#file_system ⇒ Object (readonly)
Returns the value of attribute file_system.
21 22 23 |
# File 'lib/ftpd/session.rb', line 21 def file_system @file_system end |
#logged_in ⇒ Object
Returns the value of attribute logged_in.
14 15 16 |
# File 'lib/ftpd/session.rb', line 14 def logged_in @logged_in end |
#mode=(value) ⇒ Object (writeonly)
Sets the attribute mode
23 24 25 |
# File 'lib/ftpd/session.rb', line 23 def mode=(value) @mode = value end |
#name_prefix ⇒ Object
Returns the value of attribute name_prefix.
15 16 17 |
# File 'lib/ftpd/session.rb', line 15 def name_prefix @name_prefix end |
#protection_buffer_size_set ⇒ Object
Returns the value of attribute protection_buffer_size_set.
16 17 18 |
# File 'lib/ftpd/session.rb', line 16 def protection_buffer_size_set @protection_buffer_size_set end |
#socket ⇒ Object
Returns the value of attribute socket.
17 18 19 |
# File 'lib/ftpd/session.rb', line 17 def socket @socket end |
#structure=(value) ⇒ Object (writeonly)
Sets the attribute structure
24 25 26 |
# File 'lib/ftpd/session.rb', line 24 def structure=(value) @structure = value end |
Instance Method Details
#close_data_server_socket ⇒ Object
118 119 120 121 122 |
# File 'lib/ftpd/session.rb', line 118 def close_data_server_socket return unless @data_server @data_server.close @data_server = nil end |
#command_not_needed ⇒ Object
114 115 116 |
# File 'lib/ftpd/session.rb', line 114 def command_not_needed reply '202 Command not needed at this site' end |
#ensure_logged_in ⇒ Object
60 61 62 63 |
# File 'lib/ftpd/session.rb', line 60 def ensure_logged_in return if @logged_in error "Not logged in", 530 end |
#ensure_not_epsv_all ⇒ Object
71 72 73 74 75 |
# File 'lib/ftpd/session.rb', line 71 def ensure_not_epsv_all if @epsv_all error "Not allowed after EPSV ALL", 501 end end |
#ensure_protocol_supported(protocol_code) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/ftpd/session.rb', line 81 def ensure_protocol_supported(protocol_code) unless @protocols.supports_protocol?(protocol_code) protocol_list = @protocols.protocol_codes.join(',') error("Network protocol #{protocol_code} not supported, "\ "use (#{protocol_list})", 522) end end |
#ensure_tls_supported ⇒ Object
65 66 67 68 69 |
# File 'lib/ftpd/session.rb', line 65 def ensure_tls_supported unless tls_enabled? error "TLS not enabled", 534 end end |
#execute_command(command, argument) ⇒ Object
56 57 58 |
# File 'lib/ftpd/session.rb', line 56 def execute_command command, argument @command_handlers.execute command, argument end |
#expect(command) ⇒ Object
110 111 112 |
# File 'lib/ftpd/session.rb', line 110 def expect(command) @command_sequence_checker.expect command end |
#login(*auth_tokens) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ftpd/session.rb', line 133 def login(*auth_tokens) user = auth_tokens.first unless authenticate(*auth_tokens) failed_auth error "Login incorrect", 530 end reply "230 Logged in" set_file_system @config.driver.file_system(user) @logged_in = true reset_failed_auths end |
#pwd(status_code) ⇒ Object
93 94 95 |
# File 'lib/ftpd/session.rb', line 93 def pwd(status_code) reply %Q(#{status_code} "#{@name_prefix}" is current directory) end |
#reply(s) ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/ftpd/session.rb', line 124 def reply(s) if @config.response_delay.to_i != 0 @config.log.warn "#{@config.response_delay} second delay before replying" sleep @config.response_delay end @config.log.debug s @socket.write s + "\r\n" end |
#run ⇒ Object
48 49 50 |
# File 'lib/ftpd/session.rb', line 48 def run @command_loop.read_and_execute_commands end |
#server_name_and_version ⇒ Object
153 154 155 |
# File 'lib/ftpd/session.rb', line 153 def server_name_and_version "#{@config.server_name} #{@config.server_version}" end |
#set_active_mode_address(address, port) ⇒ Object
145 146 147 148 149 150 151 |
# File 'lib/ftpd/session.rb', line 145 def set_active_mode_address(address, port) if port > 0xffff || port < 1024 && !@config.allow_low_data_ports error "Command not implemented for that parameter", 504 end @data_hostname = address @data_port = port end |
#supported_commands ⇒ Object
89 90 91 |
# File 'lib/ftpd/session.rb', line 89 def supported_commands @command_handlers.commands.map(&:upcase) end |
#tls_enabled? ⇒ Boolean
77 78 79 |
# File 'lib/ftpd/session.rb', line 77 def tls_enabled? @config.tls != :off end |
#valid_command?(command) ⇒ Boolean
52 53 54 |
# File 'lib/ftpd/session.rb', line 52 def valid_command?(command) @command_handlers.has?(command) end |