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
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdMdtm < CommandHandler
|
6
|
+
|
7
|
+
def cmd_mdtm(path)
|
8
|
+
ensure_logged_in
|
9
|
+
ensure_file_system_supports :dir
|
10
|
+
ensure_file_system_supports :file_info
|
11
|
+
syntax_error unless path
|
12
|
+
path = File.expand_path(path, name_prefix)
|
13
|
+
ensure_accessible(path)
|
14
|
+
ensure_exists(path)
|
15
|
+
info = file_system.file_info(path)
|
16
|
+
mtime = info.mtime.utc
|
17
|
+
# We would like to report fractional seconds, too. Sadly, the
|
18
|
+
# spec declares that we may not report more precision than is
|
19
|
+
# actually there, and there is no spec or API to tell us how
|
20
|
+
# many fractional digits are significant.
|
21
|
+
mtime = mtime.strftime("%Y%m%d%H%M%S")
|
22
|
+
reply "213 #{mtime}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/ftpd/cmd_mkd.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdMkd < CommandHandler
|
6
|
+
|
7
|
+
def cmd_mkd(argument)
|
8
|
+
syntax_error unless argument
|
9
|
+
ensure_logged_in
|
10
|
+
ensure_file_system_supports :mkdir
|
11
|
+
path = File.expand_path(argument, name_prefix)
|
12
|
+
ensure_accessible path
|
13
|
+
ensure_exists File.dirname(path)
|
14
|
+
ensure_directory File.dirname(path)
|
15
|
+
ensure_does_not_exist path
|
16
|
+
file_system.mkdir path
|
17
|
+
reply %Q'257 "#{path}" created'
|
18
|
+
end
|
19
|
+
alias cmd_xmkd :cmd_mkd
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdMode < CommandHandler
|
6
|
+
|
7
|
+
def cmd_mode(argument)
|
8
|
+
syntax_error unless argument
|
9
|
+
ensure_logged_in
|
10
|
+
name, implemented = TRANSMISSION_MODES[argument]
|
11
|
+
error "Invalid mode code", 504 unless name
|
12
|
+
error "Mode not implemented", 504 unless implemented
|
13
|
+
self.mode = argument
|
14
|
+
reply "200 Mode set to #{name}"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
TRANSMISSION_MODES = {
|
20
|
+
'B'=>['Block', false],
|
21
|
+
'C'=>['Compressed', false],
|
22
|
+
'S'=>['Stream', true],
|
23
|
+
}
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdNlst < CommandHandler
|
6
|
+
|
7
|
+
def cmd_nlst(argument)
|
8
|
+
close_data_server_socket_when_done do
|
9
|
+
ensure_logged_in
|
10
|
+
ensure_file_system_supports :dir
|
11
|
+
path = list_path(argument)
|
12
|
+
path = File.expand_path(path, name_prefix)
|
13
|
+
transmit_file(StringIO.new(name_list(path)), 'A')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def name_list(path)
|
20
|
+
path_list(path).map do |path|
|
21
|
+
File.basename(path) + "\n"
|
22
|
+
end.join
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdPasv < CommandHandler
|
6
|
+
|
7
|
+
def cmd_pasv(argument)
|
8
|
+
ensure_logged_in
|
9
|
+
ensure_not_epsv_all
|
10
|
+
if data_server
|
11
|
+
reply "200 Already in passive mode"
|
12
|
+
else
|
13
|
+
interface = socket.addr[3]
|
14
|
+
self.data_server = TCPServer.new(interface, 0)
|
15
|
+
ip = data_server.addr[3]
|
16
|
+
port = data_server.addr[1]
|
17
|
+
quads = [
|
18
|
+
ip.scan(/\d+/),
|
19
|
+
port >> 8,
|
20
|
+
port & 0xff,
|
21
|
+
].flatten.join(',')
|
22
|
+
reply "227 Entering passive mode (#{quads})"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdPbsz < CommandHandler
|
6
|
+
|
7
|
+
def cmd_pbsz(buffer_size)
|
8
|
+
ensure_tls_supported
|
9
|
+
syntax_error unless buffer_size =~ /^\d+$/
|
10
|
+
buffer_size = buffer_size.to_i
|
11
|
+
unless socket.encrypted?
|
12
|
+
error "PBSZ must be preceded by AUTH", 503
|
13
|
+
end
|
14
|
+
unless buffer_size == 0
|
15
|
+
error "PBSZ=0", 501
|
16
|
+
end
|
17
|
+
reply "200 PBSZ=0"
|
18
|
+
self.protection_buffer_size_set = true
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
# The Data Port (PORT) command.
|
6
|
+
|
7
|
+
class CmdPort < CommandHandler
|
8
|
+
|
9
|
+
def cmd_port(argument)
|
10
|
+
ensure_logged_in
|
11
|
+
ensure_not_epsv_all
|
12
|
+
pieces = argument.split(/,/)
|
13
|
+
syntax_error unless pieces.size == 6
|
14
|
+
pieces.collect! do |s|
|
15
|
+
syntax_error unless s =~ /^\d{1,3}$/
|
16
|
+
i = s.to_i
|
17
|
+
syntax_error unless (0..255) === i
|
18
|
+
i
|
19
|
+
end
|
20
|
+
hostname = pieces[0..3].join('.')
|
21
|
+
port = pieces[4] << 8 | pieces[5]
|
22
|
+
set_active_mode_address hostname, port
|
23
|
+
reply "200 PORT command successful"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdProt < CommandHandler
|
6
|
+
|
7
|
+
def cmd_prot(level_arg)
|
8
|
+
level_code = level_arg.upcase
|
9
|
+
unless protection_buffer_size_set
|
10
|
+
error "PROT must be preceded by PBSZ", 503
|
11
|
+
end
|
12
|
+
level = DATA_CHANNEL_PROTECTION_LEVELS[level_code]
|
13
|
+
unless level
|
14
|
+
error "Unknown protection level", 504
|
15
|
+
end
|
16
|
+
unless level == :private
|
17
|
+
error "Unsupported protection level #{level}", 536
|
18
|
+
end
|
19
|
+
self.data_channel_protection_level = level
|
20
|
+
reply "200 Data protection level #{level_code}"
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
DATA_CHANNEL_PROTECTION_LEVELS = {
|
26
|
+
'C'=>:clear,
|
27
|
+
'S'=>:safe,
|
28
|
+
'E'=>:confidential,
|
29
|
+
'P'=>:private
|
30
|
+
}
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/ftpd/cmd_pwd.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
# The Quit (QUIT) command
|
6
|
+
|
7
|
+
class CmdQuit < CommandHandler
|
8
|
+
|
9
|
+
def cmd_quit(argument)
|
10
|
+
syntax_error if argument
|
11
|
+
ensure_logged_in
|
12
|
+
reply "221 Byebye"
|
13
|
+
self.logged_in = false
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdRename < CommandHandler
|
6
|
+
|
7
|
+
def cmd_rnfr(argument)
|
8
|
+
ensure_logged_in
|
9
|
+
ensure_file_system_supports :rename
|
10
|
+
syntax_error unless argument
|
11
|
+
from_path = File.expand_path(argument, name_prefix)
|
12
|
+
ensure_accessible from_path
|
13
|
+
ensure_exists from_path
|
14
|
+
@rename_from_path = from_path
|
15
|
+
reply '350 RNFR accepted; ready for destination'
|
16
|
+
expect 'rnto'
|
17
|
+
end
|
18
|
+
|
19
|
+
def cmd_rnto(argument)
|
20
|
+
ensure_logged_in
|
21
|
+
ensure_file_system_supports :rename
|
22
|
+
syntax_error unless argument
|
23
|
+
to_path = File.expand_path(argument, name_prefix)
|
24
|
+
ensure_accessible to_path
|
25
|
+
ensure_does_not_exist to_path
|
26
|
+
file_system.rename(@rename_from_path, to_path)
|
27
|
+
reply '250 Rename successful'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdRetr < CommandHandler
|
6
|
+
|
7
|
+
def cmd_retr(argument)
|
8
|
+
close_data_server_socket_when_done do
|
9
|
+
ensure_logged_in
|
10
|
+
ensure_file_system_supports :read
|
11
|
+
path = argument
|
12
|
+
syntax_error unless path
|
13
|
+
path = File.expand_path(path, name_prefix)
|
14
|
+
ensure_accessible path
|
15
|
+
ensure_exists path
|
16
|
+
file_system.read(path) do |file|
|
17
|
+
transmit_file file
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/ftpd/cmd_rmd.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdRmd < CommandHandler
|
6
|
+
|
7
|
+
def cmd_rmd(argument)
|
8
|
+
syntax_error unless argument
|
9
|
+
ensure_logged_in
|
10
|
+
ensure_file_system_supports :rmdir
|
11
|
+
path = File.expand_path(argument, name_prefix)
|
12
|
+
ensure_accessible path
|
13
|
+
ensure_exists path
|
14
|
+
ensure_directory path
|
15
|
+
file_system.rmdir path
|
16
|
+
reply '250 RMD command successful'
|
17
|
+
end
|
18
|
+
alias cmd_xrmd :cmd_rmd
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'command_handler'
|
2
|
+
|
3
|
+
module Ftpd
|
4
|
+
|
5
|
+
class CmdSize < CommandHandler
|
6
|
+
|
7
|
+
def cmd_size(path)
|
8
|
+
ensure_logged_in
|
9
|
+
ensure_file_system_supports :read
|
10
|
+
syntax_error unless path
|
11
|
+
path = File.expand_path(path, name_prefix)
|
12
|
+
ensure_accessible(path)
|
13
|
+
ensure_exists(path)
|
14
|
+
file_system.read(path) do |file|
|
15
|
+
if data_type == 'A'
|
16
|
+
output = StringIO.new
|
17
|
+
io = Ftpd::Stream.new(output, data_type)
|
18
|
+
io.write(file)
|
19
|
+
size = output.size
|
20
|
+
else
|
21
|
+
size = file.size
|
22
|
+
end
|
23
|
+
reply "213 #{size}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|