rubysl-net-ftp 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/lib/net/ftp.rb +1 -0
  9. data/lib/net/ftptls.rb +1 -0
  10. data/lib/rubysl/net/ftp.rb +2 -0
  11. data/lib/rubysl/net/ftp/ftp.rb +926 -0
  12. data/lib/rubysl/net/ftp/version.rb +7 -0
  13. data/rubysl-net-ftp.gemspec +23 -0
  14. data/spec/FTPError_spec.rb +7 -0
  15. data/spec/FTPPermError_spec.rb +11 -0
  16. data/spec/FTPProtoError_spec.rb +11 -0
  17. data/spec/FTPReplyError_spec.rb +11 -0
  18. data/spec/FTPTempError_spec.rb +11 -0
  19. data/spec/abort_spec.rb +61 -0
  20. data/spec/acct_spec.rb +57 -0
  21. data/spec/binary_spec.rb +23 -0
  22. data/spec/chdir_spec.rb +100 -0
  23. data/spec/close_spec.rb +29 -0
  24. data/spec/closed_spec.rb +20 -0
  25. data/spec/connect_spec.rb +48 -0
  26. data/spec/debug_mode_spec.rb +22 -0
  27. data/spec/delete_spec.rb +58 -0
  28. data/spec/dir_spec.rb +7 -0
  29. data/spec/fixtures/putbinaryfile +3 -0
  30. data/spec/fixtures/puttextfile +3 -0
  31. data/spec/fixtures/server.rb +265 -0
  32. data/spec/get_spec.rb +20 -0
  33. data/spec/getbinaryfile_spec.rb +7 -0
  34. data/spec/getdir_spec.rb +6 -0
  35. data/spec/gettextfile_spec.rb +7 -0
  36. data/spec/help_spec.rb +65 -0
  37. data/spec/initialize_spec.rb +86 -0
  38. data/spec/last_response_code_spec.rb +7 -0
  39. data/spec/last_response_spec.rb +24 -0
  40. data/spec/lastresp_spec.rb +7 -0
  41. data/spec/list_spec.rb +7 -0
  42. data/spec/login_spec.rb +215 -0
  43. data/spec/ls_spec.rb +7 -0
  44. data/spec/mdtm_spec.rb +37 -0
  45. data/spec/mkdir_spec.rb +60 -0
  46. data/spec/mtime_spec.rb +49 -0
  47. data/spec/nlst_spec.rb +120 -0
  48. data/spec/noop_spec.rb +37 -0
  49. data/spec/open_spec.rb +54 -0
  50. data/spec/passive_spec.rb +23 -0
  51. data/spec/put_spec.rb +20 -0
  52. data/spec/putbinaryfile_spec.rb +7 -0
  53. data/spec/puttextfile_spec.rb +7 -0
  54. data/spec/pwd_spec.rb +52 -0
  55. data/spec/quit_spec.rb +32 -0
  56. data/spec/rename_spec.rb +93 -0
  57. data/spec/resume_spec.rb +22 -0
  58. data/spec/retrbinary_spec.rb +29 -0
  59. data/spec/retrlines_spec.rb +33 -0
  60. data/spec/return_code_spec.rb +23 -0
  61. data/spec/rmdir_spec.rb +57 -0
  62. data/spec/sendcmd_spec.rb +53 -0
  63. data/spec/set_socket_spec.rb +7 -0
  64. data/spec/shared/getbinaryfile.rb +179 -0
  65. data/spec/shared/gettextfile.rb +129 -0
  66. data/spec/shared/last_response_code.rb +25 -0
  67. data/spec/shared/list.rb +133 -0
  68. data/spec/shared/putbinaryfile.rb +232 -0
  69. data/spec/shared/puttextfile.rb +149 -0
  70. data/spec/shared/pwd.rb +3 -0
  71. data/spec/site_spec.rb +52 -0
  72. data/spec/size_spec.rb +47 -0
  73. data/spec/status_spec.rb +62 -0
  74. data/spec/storbinary_spec.rb +47 -0
  75. data/spec/storlines_spec.rb +42 -0
  76. data/spec/system_spec.rb +47 -0
  77. data/spec/voidcmd_spec.rb +53 -0
  78. data/spec/welcome_spec.rb +24 -0
  79. metadata +243 -0
@@ -0,0 +1,7 @@
1
+ module RubySL
2
+ module Net
3
+ module FTP
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/net/ftp/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-net-ftp"
6
+ spec.version = RubySL::Net::FTP::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library ftp.}
10
+ spec.summary = %q{Ruby standard library ftp.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-net-ftp"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.3"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "mspec", "~> 1.5"
22
+ spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
23
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTPError" do
4
+ it "is an Exception" do
5
+ Net::FTPError.should < Exception
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTPPermError" do
4
+ it "is an Exception" do
5
+ Net::FTPPermError.should < Exception
6
+ end
7
+
8
+ it "is a subclass of Net::FTPError" do
9
+ Net::FTPPermError.should < Net::FTPError
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTPProtoError" do
4
+ it "is an Exception" do
5
+ Net::FTPProtoError.should < Exception
6
+ end
7
+
8
+ it "is a subclass of Net::FTPError" do
9
+ Net::FTPPermError.should < Net::FTPError
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTPReplyError" do
4
+ it "is an Exception" do
5
+ Net::FTPReplyError.should < Exception
6
+ end
7
+
8
+ it "is a subclass of Net::FTPError" do
9
+ Net::FTPPermError.should < Net::FTPError
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTPTempError" do
4
+ it "is an Exception" do
5
+ Net::FTPTempError.should < Exception
6
+ end
7
+
8
+ it "is a subclass of Net::FTPError" do
9
+ Net::FTPPermError.should < Net::FTPError
10
+ end
11
+ end
@@ -0,0 +1,61 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#abort" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ it "sends the ABOR command to the server" do
20
+ lambda { @ftp.abort }.should_not raise_error
21
+ end
22
+
23
+ it "ignores the response" do
24
+ @ftp.abort
25
+ @ftp.last_response.should == "220 Dummy FTP Server ready!\n"
26
+ end
27
+
28
+ it "returns the full response" do
29
+ @ftp.abort.should == "226 Closing data connection. (ABOR)\n"
30
+ end
31
+
32
+ it "does not raise any error when the response code is 225" do
33
+ @server.should_receive(:abor).and_respond("225 Data connection open; no transfer in progress.")
34
+ lambda { @ftp.abort }.should_not raise_error
35
+ end
36
+
37
+ it "does not raise any error when the response code is 226" do
38
+ @server.should_receive(:abor).and_respond("226 Closing data connection.")
39
+ lambda { @ftp.abort }.should_not raise_error
40
+ end
41
+
42
+ it "raises a Net::FTPProtoError when the response code is 500" do
43
+ @server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.")
44
+ lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
45
+ end
46
+
47
+ it "raises a Net::FTPProtoError when the response code is 501" do
48
+ @server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.")
49
+ lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
50
+ end
51
+
52
+ it "raises a Net::FTPProtoError when the response code is 502" do
53
+ @server.should_receive(:abor).and_respond("502 Command not implemented.")
54
+ lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
55
+ end
56
+
57
+ it "raises a Net::FTPProtoError when the response code is 421" do
58
+ @server.should_receive(:abor).and_respond("421 Service not available, closing control connection.")
59
+ lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
60
+ end
61
+ end
data/spec/acct_spec.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#acct" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ it "writes the ACCT command to the server" do
20
+ @ftp.acct("my_account")
21
+ @ftp.last_response.should == "230 User 'my_account' logged in, proceed. (ACCT)\n"
22
+ end
23
+
24
+ it "returns nil" do
25
+ @ftp.acct("my_account").should == nil
26
+ end
27
+
28
+ it "does not raise any error when the response code is 230" do
29
+ @server.should_receive(:acct).and_respond("230 User logged in, proceed.")
30
+ lambda { @ftp.acct("my_account") }.should_not raise_error
31
+ end
32
+
33
+ it "raises a Net::FTPPermError when the response code is 530" do
34
+ @server.should_receive(:acct).and_respond("530 Not logged in.")
35
+ lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
36
+ end
37
+
38
+ it "raises a Net::FTPPermError when the response code is 500" do
39
+ @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
40
+ lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
41
+ end
42
+
43
+ it "raises a Net::FTPPermError when the response code is 501" do
44
+ @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
45
+ lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
46
+ end
47
+
48
+ it "raises a Net::FTPPermError when the response code is 503" do
49
+ @server.should_receive(:acct).and_respond("503 Bad sequence of commands.")
50
+ lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
51
+ end
52
+
53
+ it "raises a Net::FTPTempError when the response code is 421" do
54
+ @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
55
+ lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPTempError)
56
+ end
57
+ end
@@ -0,0 +1,23 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#binary" do
4
+ it "returns true when self is in binary mode" do
5
+ ftp = Net::FTP.new
6
+ ftp.binary.should be_true
7
+
8
+ ftp.binary = false
9
+ ftp.binary.should be_false
10
+ end
11
+ end
12
+
13
+ describe "Net::FTP#binary=" do
14
+ it "sets self to binary mode when passed true" do
15
+ ftp = Net::FTP.new
16
+
17
+ ftp.binary = true
18
+ ftp.binary.should be_true
19
+
20
+ ftp.binary = false
21
+ ftp.binary.should be_false
22
+ end
23
+ end
@@ -0,0 +1,100 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#chdir" do
5
+ before(:each) do
6
+ @server = NetFTPSpecs::DummyFTP.new
7
+ @server.serve_once
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ end
12
+
13
+ after(:each) do
14
+ @ftp.quit rescue nil
15
+ @ftp.close
16
+ @server.stop
17
+ end
18
+
19
+ describe "when switching to the parent directory" do
20
+ it "sends the 'CDUP' command to the server" do
21
+ @ftp.chdir("..")
22
+ @ftp.last_response.should == "200 Command okay. (CDUP)\n"
23
+ end
24
+
25
+ it "returns nil" do
26
+ @ftp.chdir("..").should be_nil
27
+ end
28
+
29
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/384", "1.8.7" do
30
+ it "does not raise a Net::FTPPermError when the response code is 500" do
31
+ @server.should_receive(:cdup).and_respond("500 Syntax error, command unrecognized.")
32
+ lambda { @ftp.chdir("..") }.should_not raise_error(Net::FTPPermError)
33
+ end
34
+
35
+ it "raises a Net::FTPPermError when the response code is 501" do
36
+ @server.should_receive(:cdup).and_respond("501 Syntax error in parameters or arguments.")
37
+ lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
38
+ end
39
+
40
+ it "raises a Net::FTPPermError when the response code is 502" do
41
+ @server.should_receive(:cdup).and_respond("502 Command not implemented.")
42
+ lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
43
+ end
44
+
45
+ it "raises a Net::FTPTempError when the response code is 421" do
46
+ @server.should_receive(:cdup).and_respond("421 Service not available, closing control connection.")
47
+ lambda { @ftp.chdir("..") }.should raise_error(Net::FTPTempError)
48
+ end
49
+
50
+ it "raises a Net::FTPPermError when the response code is 530" do
51
+ @server.should_receive(:cdup).and_respond("530 Not logged in.")
52
+ lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
53
+ end
54
+
55
+ it "raises a Net::FTPPermError when the response code is 550" do
56
+ @server.should_receive(:cdup).and_respond("550 Requested action not taken.")
57
+ lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
58
+ end
59
+ end
60
+ end
61
+
62
+ it "writes the 'CWD' command with the passed directory to the socket" do
63
+ @ftp.chdir("test")
64
+ @ftp.last_response.should == "200 Command okay. (CWD test)\n"
65
+ end
66
+
67
+ it "returns nil" do
68
+ @ftp.chdir("test").should be_nil
69
+ end
70
+
71
+ it "raises a Net::FTPPermError when the response code is 500" do
72
+ @server.should_receive(:cwd).and_respond("500 Syntax error, command unrecognized.")
73
+ lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
74
+ end
75
+
76
+ it "raises a Net::FTPPermError when the response code is 501" do
77
+ @server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.")
78
+ lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
79
+ end
80
+
81
+ it "raises a Net::FTPPermError when the response code is 502" do
82
+ @server.should_receive(:cwd).and_respond("502 Command not implemented.")
83
+ lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
84
+ end
85
+
86
+ it "raises a Net::FTPTempError when the response code is 421" do
87
+ @server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.")
88
+ lambda { @ftp.chdir("test") }.should raise_error(Net::FTPTempError)
89
+ end
90
+
91
+ it "raises a Net::FTPPermError when the response code is 530" do
92
+ @server.should_receive(:cwd).and_respond("530 Not logged in.")
93
+ lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
94
+ end
95
+
96
+ it "raises a Net::FTPPermError when the response code is 550" do
97
+ @server.should_receive(:cwd).and_respond("550 Requested action not taken.")
98
+ lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
99
+ end
100
+ end
@@ -0,0 +1,29 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#close" do
4
+ before(:each) do
5
+ @socket = mock("Socket")
6
+ @socket.stub!(:closed?).and_return(false)
7
+ @socket.stub!(:read_timeout).and_return(60)
8
+ @socket.stub!(:read_timeout=).and_return(3)
9
+
10
+ @ftp = Net::FTP.new
11
+ @ftp.instance_variable_set(:@sock, @socket)
12
+ end
13
+
14
+ it "closes the socket" do
15
+ @socket.should_receive(:close)
16
+ @ftp.close.should be_nil
17
+ end
18
+
19
+ it "does not try to close the socket if it has already been closed" do
20
+ @socket.should_receive(:closed?).and_return(true)
21
+ @socket.should_not_receive(:close)
22
+ @ftp.close.should be_nil
23
+ end
24
+
25
+ it "does not try to close the socket if it is nil" do
26
+ @ftp.instance_variable_set(:@sock, nil)
27
+ @ftp.close.should be_nil
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#closed?" do
4
+ before(:each) do
5
+ @socket = mock("Socket")
6
+
7
+ @ftp = Net::FTP.new
8
+ @ftp.instance_variable_set(:@sock, @socket)
9
+ end
10
+
11
+ it "returns true when the socket is closed" do
12
+ @socket.should_receive(:closed?).and_return(true)
13
+ @ftp.closed?.should be_true
14
+ end
15
+
16
+ it "returns true when the socket is nil" do
17
+ @ftp.instance_variable_set(:@sock, nil)
18
+ @ftp.closed?.should be_true
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ # TODO: Add specs for using the SOCKSSocket
5
+ describe "Net::FTP#connect" do
6
+ before(:each) do
7
+ @server = NetFTPSpecs::DummyFTP.new
8
+ @server.serve_once
9
+
10
+ @ftp = Net::FTP.new
11
+ end
12
+
13
+ after(:each) do
14
+ @server.connect_message = nil
15
+ @ftp.quit rescue nil
16
+ @ftp.close
17
+ @server.stop
18
+ end
19
+
20
+ it "tries to connect to the FTP Server on the given host and port" do
21
+ lambda { @ftp.connect("localhost", 9921) }.should_not raise_error
22
+ end
23
+
24
+ it "returns nil" do
25
+ @ftp.connect("localhost", 9921).should be_nil
26
+ end
27
+
28
+ it "prints a small debug line when in debug mode" do
29
+ @ftp.debug_mode = true
30
+ lambda { @ftp.connect("localhost", 9921) }.should output(/#{"connect: localhost, 9921\\nget: 220 Dummy FTP Server ready!"}/)
31
+ @ftp.debug_mode = false
32
+ end
33
+
34
+ it "does not raise any error when the response code is 220" do
35
+ @server.connect_message = "220 Dummy FTP Server ready!"
36
+ lambda { @ftp.connect("localhost", 9921) }.should_not raise_error
37
+ end
38
+
39
+ it "raises a Net::FTPReplyError when the response code is 120" do
40
+ @server.connect_message = "120 Service ready in nnn minutes."
41
+ lambda { @ftp.connect("localhost", 9921) }.should raise_error(Net::FTPReplyError)
42
+ end
43
+
44
+ it "raises a Net::FTPTempError when the response code is 421" do
45
+ @server.connect_message = "421 Service not available, closing control connection."
46
+ lambda { @ftp.connect("localhost", 9921) }.should raise_error(Net::FTPTempError)
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#debug_mode" do
4
+ it "returns true when self is in debug mode" do
5
+ ftp = Net::FTP.new
6
+ ftp.debug_mode.should be_false
7
+
8
+ ftp.debug_mode = true
9
+ ftp.debug_mode.should be_true
10
+ end
11
+ end
12
+
13
+ describe "Net::FTP#debug_mode=" do
14
+ it "sets self into debug mode when passed true" do
15
+ ftp = Net::FTP.new
16
+ ftp.debug_mode = true
17
+ ftp.debug_mode.should be_true
18
+
19
+ ftp.debug_mode = false
20
+ ftp.debug_mode.should be_false
21
+ end
22
+ end