investtools-ftpd 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +5 -0
- data/.yardopts +7 -0
- data/Changelog.md +310 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +93 -0
- data/LICENSE.md +9 -0
- data/README.md +371 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/doc/benchmarks.md +82 -0
- data/doc/references.md +66 -0
- data/doc/rfc-compliance.md +292 -0
- data/examples/example.rb +275 -0
- data/examples/example_spec.rb +93 -0
- data/examples/hello_world.rb +32 -0
- data/features/example/eplf.feature +14 -0
- data/features/example/example.feature +18 -0
- data/features/example/read_only.feature +63 -0
- data/features/example/step_definitions/example_server.rb +11 -0
- data/features/ftp_server/abort.feature +13 -0
- data/features/ftp_server/allo.feature +33 -0
- data/features/ftp_server/append.feature +94 -0
- data/features/ftp_server/cdup.feature +36 -0
- data/features/ftp_server/command_errors.feature +13 -0
- data/features/ftp_server/concurrent_sessions.feature +14 -0
- data/features/ftp_server/delay_after_failed_login.feature +23 -0
- data/features/ftp_server/delete.feature +60 -0
- data/features/ftp_server/directory_navigation.feature +59 -0
- data/features/ftp_server/disconnect_after_failed_logins.feature +25 -0
- data/features/ftp_server/eprt.feature +55 -0
- data/features/ftp_server/epsv.feature +36 -0
- data/features/ftp_server/features.feature +38 -0
- data/features/ftp_server/file_structure.feature +43 -0
- data/features/ftp_server/get.feature +80 -0
- data/features/ftp_server/get_ipv6.feature +43 -0
- data/features/ftp_server/get_tls.feature +23 -0
- data/features/ftp_server/help.feature +21 -0
- data/features/ftp_server/implicit_tls.feature +23 -0
- data/features/ftp_server/invertability.feature +15 -0
- data/features/ftp_server/list.feature +94 -0
- data/features/ftp_server/list_tls.feature +29 -0
- data/features/ftp_server/logging.feature +11 -0
- data/features/ftp_server/login_auth_level_account.feature +51 -0
- data/features/ftp_server/login_auth_level_password.feature +59 -0
- data/features/ftp_server/login_auth_level_user.feature +31 -0
- data/features/ftp_server/max_connections.feature +39 -0
- data/features/ftp_server/mdtm.feature +53 -0
- data/features/ftp_server/mkdir.feature +70 -0
- data/features/ftp_server/mode.feature +43 -0
- data/features/ftp_server/name_list.feature +77 -0
- data/features/ftp_server/name_list_tls.feature +30 -0
- data/features/ftp_server/noop.feature +17 -0
- data/features/ftp_server/options.feature +17 -0
- data/features/ftp_server/pasv.feature +23 -0
- data/features/ftp_server/port.feature +49 -0
- data/features/ftp_server/put.feature +79 -0
- data/features/ftp_server/put_tls.feature +23 -0
- data/features/ftp_server/put_unique.feature +56 -0
- data/features/ftp_server/quit.feature +23 -0
- data/features/ftp_server/reinitialize.feature +13 -0
- data/features/ftp_server/rename.feature +97 -0
- data/features/ftp_server/rmdir.feature +71 -0
- data/features/ftp_server/site.feature +13 -0
- data/features/ftp_server/size.feature +69 -0
- data/features/ftp_server/status.feature +18 -0
- data/features/ftp_server/step_definitions/logging.rb +8 -0
- data/features/ftp_server/step_definitions/test_server.rb +65 -0
- data/features/ftp_server/structure_mount.feature +13 -0
- data/features/ftp_server/syntax_errors.feature +18 -0
- data/features/ftp_server/syst.feature +18 -0
- data/features/ftp_server/timeout.feature +26 -0
- data/features/ftp_server/type.feature +59 -0
- data/features/step_definitions/append.rb +15 -0
- data/features/step_definitions/client.rb +24 -0
- data/features/step_definitions/client_and_server_files.rb +24 -0
- data/features/step_definitions/client_files.rb +14 -0
- data/features/step_definitions/command.rb +5 -0
- data/features/step_definitions/connect.rb +37 -0
- data/features/step_definitions/delete.rb +15 -0
- data/features/step_definitions/directory_navigation.rb +26 -0
- data/features/step_definitions/error_replies.rb +115 -0
- data/features/step_definitions/features.rb +21 -0
- data/features/step_definitions/file_structure.rb +16 -0
- data/features/step_definitions/generic_send.rb +9 -0
- data/features/step_definitions/get.rb +16 -0
- data/features/step_definitions/help.rb +18 -0
- data/features/step_definitions/invalid_commands.rb +11 -0
- data/features/step_definitions/line_endings.rb +7 -0
- data/features/step_definitions/list.rb +73 -0
- data/features/step_definitions/login.rb +82 -0
- data/features/step_definitions/mkdir.rb +9 -0
- data/features/step_definitions/mode.rb +15 -0
- data/features/step_definitions/mtime.rb +23 -0
- data/features/step_definitions/noop.rb +15 -0
- data/features/step_definitions/options.rb +9 -0
- data/features/step_definitions/passive.rb +3 -0
- data/features/step_definitions/pending.rb +3 -0
- data/features/step_definitions/port.rb +5 -0
- data/features/step_definitions/put.rb +29 -0
- data/features/step_definitions/quit.rb +15 -0
- data/features/step_definitions/rename.rb +11 -0
- data/features/step_definitions/rmdir.rb +9 -0
- data/features/step_definitions/server_files.rb +61 -0
- data/features/step_definitions/server_title.rb +12 -0
- data/features/step_definitions/size.rb +20 -0
- data/features/step_definitions/status.rb +9 -0
- data/features/step_definitions/success_replies.rb +7 -0
- data/features/step_definitions/system.rb +7 -0
- data/features/step_definitions/timing.rb +19 -0
- data/features/step_definitions/type.rb +15 -0
- data/features/support/env.rb +4 -0
- data/features/support/example_server.rb +67 -0
- data/features/support/file_templates/ascii_unix +4 -0
- data/features/support/file_templates/ascii_windows +4 -0
- data/features/support/file_templates/binary +0 -0
- data/features/support/test_client.rb +250 -0
- data/features/support/test_file_templates.rb +33 -0
- data/features/support/test_server.rb +293 -0
- data/features/support/test_server_files.rb +57 -0
- data/ftpd.gemspec +283 -0
- data/insecure-test-cert.pem +29 -0
- data/investtools-ftpd.gemspec +284 -0
- data/lib/ftpd.rb +86 -0
- data/lib/ftpd/auth_levels.rb +9 -0
- data/lib/ftpd/cmd_abor.rb +13 -0
- data/lib/ftpd/cmd_allo.rb +20 -0
- data/lib/ftpd/cmd_appe.rb +24 -0
- data/lib/ftpd/cmd_auth.rb +21 -0
- data/lib/ftpd/cmd_cdup.rb +16 -0
- data/lib/ftpd/cmd_cwd.rb +20 -0
- data/lib/ftpd/cmd_dele.rb +21 -0
- data/lib/ftpd/cmd_eprt.rb +23 -0
- data/lib/ftpd/cmd_epsv.rb +30 -0
- data/lib/ftpd/cmd_feat.rb +44 -0
- data/lib/ftpd/cmd_help.rb +29 -0
- data/lib/ftpd/cmd_list.rb +33 -0
- data/lib/ftpd/cmd_login.rb +60 -0
- data/lib/ftpd/cmd_mdtm.rb +27 -0
- data/lib/ftpd/cmd_mkd.rb +23 -0
- data/lib/ftpd/cmd_mode.rb +27 -0
- data/lib/ftpd/cmd_nlst.rb +27 -0
- data/lib/ftpd/cmd_noop.rb +14 -0
- data/lib/ftpd/cmd_opts.rb +14 -0
- data/lib/ftpd/cmd_pasv.rb +28 -0
- data/lib/ftpd/cmd_pbsz.rb +23 -0
- data/lib/ftpd/cmd_port.rb +28 -0
- data/lib/ftpd/cmd_prot.rb +34 -0
- data/lib/ftpd/cmd_pwd.rb +15 -0
- data/lib/ftpd/cmd_quit.rb +18 -0
- data/lib/ftpd/cmd_rein.rb +13 -0
- data/lib/ftpd/cmd_rename.rb +32 -0
- data/lib/ftpd/cmd_rest.rb +13 -0
- data/lib/ftpd/cmd_retr.rb +24 -0
- data/lib/ftpd/cmd_rmd.rb +22 -0
- data/lib/ftpd/cmd_site.rb +13 -0
- data/lib/ftpd/cmd_size.rb +29 -0
- data/lib/ftpd/cmd_smnt.rb +13 -0
- data/lib/ftpd/cmd_stat.rb +15 -0
- data/lib/ftpd/cmd_stor.rb +25 -0
- data/lib/ftpd/cmd_stou.rb +25 -0
- data/lib/ftpd/cmd_stru.rb +27 -0
- data/lib/ftpd/cmd_syst.rb +16 -0
- data/lib/ftpd/cmd_type.rb +28 -0
- data/lib/ftpd/command_handler.rb +90 -0
- data/lib/ftpd/command_handler_factory.rb +51 -0
- data/lib/ftpd/command_handlers.rb +60 -0
- data/lib/ftpd/command_loop.rb +80 -0
- data/lib/ftpd/command_sequence_checker.rb +58 -0
- data/lib/ftpd/config.rb +13 -0
- data/lib/ftpd/connection_throttle.rb +56 -0
- data/lib/ftpd/connection_tracker.rb +82 -0
- data/lib/ftpd/data_connection_helper.rb +123 -0
- data/lib/ftpd/disk_file_system.rb +434 -0
- data/lib/ftpd/error.rb +21 -0
- data/lib/ftpd/exception_translator.rb +32 -0
- data/lib/ftpd/exceptions.rb +62 -0
- data/lib/ftpd/file_info.rb +115 -0
- data/lib/ftpd/file_system_helper.rb +67 -0
- data/lib/ftpd/ftp_server.rb +214 -0
- data/lib/ftpd/gets_peer_address.rb +41 -0
- data/lib/ftpd/insecure_certificate.rb +16 -0
- data/lib/ftpd/list_format/eplf.rb +74 -0
- data/lib/ftpd/list_format/ls.rb +154 -0
- data/lib/ftpd/list_path.rb +28 -0
- data/lib/ftpd/null_logger.rb +22 -0
- data/lib/ftpd/protocols.rb +60 -0
- data/lib/ftpd/read_only_disk_file_system.rb +22 -0
- data/lib/ftpd/server.rb +139 -0
- data/lib/ftpd/session.rb +220 -0
- data/lib/ftpd/session_config.rb +111 -0
- data/lib/ftpd/stream.rb +80 -0
- data/lib/ftpd/telnet.rb +114 -0
- data/lib/ftpd/temp_dir.rb +22 -0
- data/lib/ftpd/tls_server.rb +111 -0
- data/lib/ftpd/translate_exceptions.rb +68 -0
- data/rake_tasks/cucumber.rake +9 -0
- data/rake_tasks/default.rake +1 -0
- data/rake_tasks/jeweler.rake +52 -0
- data/rake_tasks/spec.rake +3 -0
- data/rake_tasks/test.rake +2 -0
- data/rake_tasks/yard.rake +3 -0
- data/spec/command_sequence_checker_spec.rb +83 -0
- data/spec/connection_throttle_spec.rb +99 -0
- data/spec/connection_tracker_spec.rb +97 -0
- data/spec/disk_file_system_spec.rb +320 -0
- data/spec/exception_translator_spec.rb +36 -0
- data/spec/file_info_spec.rb +59 -0
- data/spec/ftp_server_error_spec.rb +13 -0
- data/spec/list_format/eplf_spec.rb +61 -0
- data/spec/list_format/ls_spec.rb +270 -0
- data/spec/list_path_spec.rb +21 -0
- data/spec/null_logger_spec.rb +24 -0
- data/spec/protocols_spec.rb +139 -0
- data/spec/server_spec.rb +81 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/telnet_spec.rb +75 -0
- data/spec/translate_exceptions_spec.rb +40 -0
- metadata +404 -0
data/lib/ftpd.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Standard libraries
|
2
|
+
require 'fileutils'
|
3
|
+
require 'forwardable'
|
4
|
+
require 'logger'
|
5
|
+
require 'openssl'
|
6
|
+
require 'pathname'
|
7
|
+
require 'shellwords'
|
8
|
+
require 'socket'
|
9
|
+
require 'strscan'
|
10
|
+
require 'thread'
|
11
|
+
require 'tmpdir'
|
12
|
+
|
13
|
+
# Gems
|
14
|
+
require 'memoizer'
|
15
|
+
|
16
|
+
# Ftpd
|
17
|
+
require_relative 'ftpd/auth_levels'
|
18
|
+
require_relative 'ftpd/cmd_abor'
|
19
|
+
require_relative 'ftpd/cmd_allo'
|
20
|
+
require_relative 'ftpd/cmd_appe'
|
21
|
+
require_relative 'ftpd/cmd_auth'
|
22
|
+
require_relative 'ftpd/cmd_cdup'
|
23
|
+
require_relative 'ftpd/cmd_cwd'
|
24
|
+
require_relative 'ftpd/cmd_dele'
|
25
|
+
require_relative 'ftpd/cmd_eprt'
|
26
|
+
require_relative 'ftpd/cmd_epsv'
|
27
|
+
require_relative 'ftpd/cmd_feat'
|
28
|
+
require_relative 'ftpd/cmd_help'
|
29
|
+
require_relative 'ftpd/cmd_list'
|
30
|
+
require_relative 'ftpd/cmd_login'
|
31
|
+
require_relative 'ftpd/cmd_mdtm'
|
32
|
+
require_relative 'ftpd/cmd_mkd'
|
33
|
+
require_relative 'ftpd/cmd_mode'
|
34
|
+
require_relative 'ftpd/cmd_nlst'
|
35
|
+
require_relative 'ftpd/cmd_noop'
|
36
|
+
require_relative 'ftpd/cmd_opts'
|
37
|
+
require_relative 'ftpd/cmd_pasv'
|
38
|
+
require_relative 'ftpd/cmd_pbsz'
|
39
|
+
require_relative 'ftpd/cmd_port'
|
40
|
+
require_relative 'ftpd/cmd_prot'
|
41
|
+
require_relative 'ftpd/cmd_pwd'
|
42
|
+
require_relative 'ftpd/cmd_quit'
|
43
|
+
require_relative 'ftpd/cmd_rein'
|
44
|
+
require_relative 'ftpd/cmd_rename'
|
45
|
+
require_relative 'ftpd/cmd_rest'
|
46
|
+
require_relative 'ftpd/cmd_retr'
|
47
|
+
require_relative 'ftpd/cmd_rmd'
|
48
|
+
require_relative 'ftpd/cmd_site'
|
49
|
+
require_relative 'ftpd/cmd_size'
|
50
|
+
require_relative 'ftpd/cmd_smnt'
|
51
|
+
require_relative 'ftpd/cmd_stat'
|
52
|
+
require_relative 'ftpd/cmd_stor'
|
53
|
+
require_relative 'ftpd/cmd_stou'
|
54
|
+
require_relative 'ftpd/cmd_stru'
|
55
|
+
require_relative 'ftpd/cmd_syst'
|
56
|
+
require_relative 'ftpd/cmd_type'
|
57
|
+
require_relative 'ftpd/command_handler'
|
58
|
+
require_relative 'ftpd/command_handler_factory'
|
59
|
+
require_relative 'ftpd/command_handlers'
|
60
|
+
require_relative 'ftpd/command_loop'
|
61
|
+
require_relative 'ftpd/command_sequence_checker'
|
62
|
+
require_relative 'ftpd/connection_throttle'
|
63
|
+
require_relative 'ftpd/connection_tracker'
|
64
|
+
require_relative 'ftpd/data_connection_helper'
|
65
|
+
require_relative 'ftpd/disk_file_system'
|
66
|
+
require_relative 'ftpd/error'
|
67
|
+
require_relative 'ftpd/exception_translator'
|
68
|
+
require_relative 'ftpd/exceptions'
|
69
|
+
require_relative 'ftpd/file_info'
|
70
|
+
require_relative 'ftpd/file_system_helper'
|
71
|
+
require_relative 'ftpd/ftp_server'
|
72
|
+
require_relative 'ftpd/insecure_certificate'
|
73
|
+
require_relative 'ftpd/list_format/eplf'
|
74
|
+
require_relative 'ftpd/list_format/ls'
|
75
|
+
require_relative 'ftpd/list_path'
|
76
|
+
require_relative 'ftpd/null_logger'
|
77
|
+
require_relative 'ftpd/protocols'
|
78
|
+
require_relative 'ftpd/read_only_disk_file_system'
|
79
|
+
require_relative 'ftpd/server'
|
80
|
+
require_relative 'ftpd/session'
|
81
|
+
require_relative 'ftpd/session_config'
|
82
|
+
require_relative 'ftpd/stream'
|
83
|
+
require_relative 'ftpd/telnet'
|
84
|
+
require_relative 'ftpd/temp_dir'
|
85
|
+
require_relative 'ftpd/tls_server'
|
86
|
+
require_relative 'ftpd/translate_exceptions'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
# The Allocate (ALLO) command.
|
6
|
+
#
|
7
|
+
# This server does not need the ALLO command, so treats it as a
|
8
|
+
# NOOP.
|
9
|
+
|
10
|
+
class CmdAllo < CommandHandler
|
11
|
+
|
12
|
+
def cmd_allo(argument)
|
13
|
+
ensure_logged_in
|
14
|
+
syntax_error unless argument =~ /^\d+( R \d+)?$/
|
15
|
+
command_not_needed
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdAppe < CommandHandler
|
6
|
+
|
7
|
+
def cmd_appe(argument)
|
8
|
+
close_data_server_socket_when_done do
|
9
|
+
ensure_logged_in
|
10
|
+
ensure_file_system_supports :append
|
11
|
+
path = argument
|
12
|
+
syntax_error unless path
|
13
|
+
path = File.expand_path(path, name_prefix)
|
14
|
+
ensure_accessible path
|
15
|
+
receive_file do |data_socket|
|
16
|
+
file_system.append path, data_socket
|
17
|
+
end
|
18
|
+
reply "226 Transfer complete"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdAuth < CommandHandler
|
6
|
+
|
7
|
+
def cmd_auth(security_scheme)
|
8
|
+
ensure_tls_supported
|
9
|
+
if socket.encrypted?
|
10
|
+
error "AUTH already done", 503
|
11
|
+
end
|
12
|
+
unless security_scheme =~ /^TLS(-C)?$/i
|
13
|
+
error "Security scheme not implemented: #{security_scheme}", 504
|
14
|
+
end
|
15
|
+
reply "234 AUTH #{security_scheme} OK."
|
16
|
+
socket.encrypt
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/ftpd/cmd_cwd.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdCwd < CommandHandler
|
6
|
+
|
7
|
+
def cmd_cwd(argument)
|
8
|
+
ensure_logged_in
|
9
|
+
path = File.expand_path(argument, name_prefix)
|
10
|
+
ensure_accessible path
|
11
|
+
ensure_exists path
|
12
|
+
ensure_directory path
|
13
|
+
self.name_prefix = path
|
14
|
+
pwd 250
|
15
|
+
end
|
16
|
+
alias cmd_xcwd :cmd_cwd
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdDele < CommandHandler
|
6
|
+
|
7
|
+
def cmd_dele(argument)
|
8
|
+
ensure_logged_in
|
9
|
+
ensure_file_system_supports :delete
|
10
|
+
path = argument
|
11
|
+
error "Path required", 501 unless path
|
12
|
+
path = File.expand_path(path, name_prefix)
|
13
|
+
ensure_accessible path
|
14
|
+
ensure_exists path
|
15
|
+
file_system.delete path
|
16
|
+
reply "250 DELE command successful"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdEprt < CommandHandler
|
6
|
+
|
7
|
+
def cmd_eprt(argument)
|
8
|
+
ensure_logged_in
|
9
|
+
ensure_not_epsv_all
|
10
|
+
delim = argument[0..0]
|
11
|
+
parts = argument.split(delim)[1..-1]
|
12
|
+
syntax_error unless parts.size == 3
|
13
|
+
protocol_code, address, port = *parts
|
14
|
+
protocol_code = protocol_code.to_i
|
15
|
+
ensure_protocol_supported protocol_code
|
16
|
+
port = port.to_i
|
17
|
+
set_active_mode_address address, port
|
18
|
+
reply "200 EPRT command successful"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdEpsv < CommandHandler
|
6
|
+
|
7
|
+
def cmd_epsv(argument)
|
8
|
+
ensure_logged_in
|
9
|
+
if data_server
|
10
|
+
reply "200 Already in passive mode"
|
11
|
+
else
|
12
|
+
if argument == 'ALL'
|
13
|
+
self.epsv_all = true
|
14
|
+
reply "220 EPSV now required for port setup"
|
15
|
+
else
|
16
|
+
protocol_code = argument && argument.to_i
|
17
|
+
if protocol_code
|
18
|
+
ensure_protocol_supported protocol_code
|
19
|
+
end
|
20
|
+
interface = socket.addr[3]
|
21
|
+
self.data_server = TCPServer.new(interface, 0)
|
22
|
+
port = data_server.addr[1]
|
23
|
+
reply "229 Entering extended passive mode (|||#{port}|)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdFeat < CommandHandler
|
6
|
+
|
7
|
+
def cmd_feat(argument)
|
8
|
+
syntax_error if argument
|
9
|
+
reply '211-Extensions supported:'
|
10
|
+
extensions.each do |extension|
|
11
|
+
reply " #{extension}"
|
12
|
+
end
|
13
|
+
reply '211 END'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def extensions
|
19
|
+
[
|
20
|
+
(TLS_EXTENSIONS if tls_enabled?),
|
21
|
+
IPV6_EXTENSIONS,
|
22
|
+
RFC_3659_EXTENSIONS,
|
23
|
+
].flatten.compact
|
24
|
+
end
|
25
|
+
|
26
|
+
TLS_EXTENSIONS = [
|
27
|
+
'AUTH TLS',
|
28
|
+
'PBSZ',
|
29
|
+
'PROT'
|
30
|
+
]
|
31
|
+
|
32
|
+
IPV6_EXTENSIONS = [
|
33
|
+
'EPRT',
|
34
|
+
'EPSV',
|
35
|
+
]
|
36
|
+
|
37
|
+
RFC_3659_EXTENSIONS = [
|
38
|
+
'MDTM',
|
39
|
+
'SIZE',
|
40
|
+
]
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdHelp < CommandHandler
|
6
|
+
|
7
|
+
def cmd_help(argument)
|
8
|
+
if argument
|
9
|
+
command = argument.upcase
|
10
|
+
if supported_commands.include?(command)
|
11
|
+
reply "214 Command #{command} is recognized"
|
12
|
+
else
|
13
|
+
reply "214 Command #{command} is not recognized"
|
14
|
+
end
|
15
|
+
else
|
16
|
+
reply '214-The following commands are recognized:'
|
17
|
+
supported_commands.sort.each_slice(8) do |commands|
|
18
|
+
line = commands.map do |command|
|
19
|
+
' %-4s' % command
|
20
|
+
end.join
|
21
|
+
reply line
|
22
|
+
end
|
23
|
+
reply '214 Have a nice day.'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdList < CommandHandler
|
6
|
+
|
7
|
+
def cmd_list(argument)
|
8
|
+
close_data_server_socket_when_done do
|
9
|
+
ensure_logged_in
|
10
|
+
ensure_file_system_supports :dir
|
11
|
+
ensure_file_system_supports :file_info
|
12
|
+
path = list_path(argument)
|
13
|
+
path = File.expand_path(path, name_prefix)
|
14
|
+
transmit_file(StringIO.new(list(path)), 'A')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def list(path)
|
21
|
+
format_list(path_list(path))
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_list(paths)
|
25
|
+
paths.map do |path|
|
26
|
+
file_info = file_system.file_info(path)
|
27
|
+
config.list_formatter.new(file_info).to_s + "\n"
|
28
|
+
end.join
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
# The login commands
|
6
|
+
|
7
|
+
class CmdLogin < CommandHandler
|
8
|
+
|
9
|
+
# @return [String] The user for the current login sequence
|
10
|
+
|
11
|
+
attr_accessor :user
|
12
|
+
|
13
|
+
# @return [String] The password for the current login sequence
|
14
|
+
|
15
|
+
attr_accessor :password
|
16
|
+
|
17
|
+
def initialize(*)
|
18
|
+
super
|
19
|
+
@user = nil
|
20
|
+
@password = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# * User Name (USER) command.
|
24
|
+
|
25
|
+
def cmd_user(argument)
|
26
|
+
syntax_error unless argument
|
27
|
+
sequence_error if logged_in
|
28
|
+
@user = argument
|
29
|
+
if config.auth_level > AUTH_USER
|
30
|
+
reply "331 Password required"
|
31
|
+
expect 'pass'
|
32
|
+
else
|
33
|
+
login @user
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# The Password (PASS) command
|
38
|
+
|
39
|
+
def cmd_pass(argument)
|
40
|
+
syntax_error unless argument
|
41
|
+
@password = argument
|
42
|
+
if config.auth_level > AUTH_PASSWORD
|
43
|
+
reply "332 Account required"
|
44
|
+
expect 'acct'
|
45
|
+
else
|
46
|
+
login @user, @password
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# The Account (ACCT) command
|
51
|
+
|
52
|
+
def cmd_acct(argument)
|
53
|
+
syntax_error unless argument
|
54
|
+
account = argument
|
55
|
+
login @user, @password, account
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|