rubysl-net-ftp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,86 @@
1
+ require 'net/ftp'
2
+
3
+ describe "Net::FTP#initialize" do
4
+ before(:each) do
5
+ @ftp = Net::FTP.allocate
6
+ @ftp.stub!(:connect)
7
+ end
8
+
9
+ it "is private" do
10
+ Net::FTP.should have_private_instance_method(:initialize)
11
+ end
12
+
13
+ it "sets self into binary mode" do
14
+ @ftp.binary.should be_nil
15
+ @ftp.send(:initialize)
16
+ @ftp.binary.should be_true
17
+ end
18
+
19
+ it "sets self into active mode" do
20
+ @ftp.passive.should be_nil
21
+ @ftp.send(:initialize)
22
+ @ftp.passive.should be_false
23
+ end
24
+
25
+ it "sets self into non-debug mode" do
26
+ @ftp.debug_mode.should be_nil
27
+ @ftp.send(:initialize)
28
+ @ftp.debug_mode.should be_false
29
+ end
30
+
31
+ it "sets self to not resume file uploads/downloads" do
32
+ @ftp.resume.should be_nil
33
+ @ftp.send(:initialize)
34
+ @ftp.resume.should be_false
35
+ end
36
+
37
+ describe "when passed no arguments" do
38
+ it "does not try to connect" do
39
+ @ftp.should_not_receive(:connect)
40
+ @ftp.send(:initialize)
41
+ end
42
+ end
43
+
44
+ describe "when passed host" do
45
+ it "tries to connect to the passed host" do
46
+ @ftp.should_receive(:connect).with("localhost")
47
+ @ftp.send(:initialize, "localhost")
48
+ end
49
+ end
50
+
51
+ describe "when passed host, user" do
52
+ it "tries to connect to the passed host" do
53
+ @ftp.should_receive(:connect).with("localhost")
54
+ @ftp.send(:initialize, "localhost")
55
+ end
56
+
57
+ it "tries to login with the passed username" do
58
+ @ftp.should_receive(:login).with("rubyspec", nil, nil)
59
+ @ftp.send(:initialize, "localhost", "rubyspec")
60
+ end
61
+ end
62
+
63
+ describe "when passed host, user, password" do
64
+ it "tries to connect to the passed host" do
65
+ @ftp.should_receive(:connect).with("localhost")
66
+ @ftp.send(:initialize, "localhost")
67
+ end
68
+
69
+ it "tries to login with the passed username and password" do
70
+ @ftp.should_receive(:login).with("rubyspec", "rocks", nil)
71
+ @ftp.send(:initialize, "localhost", "rubyspec", "rocks")
72
+ end
73
+ end
74
+
75
+ describe "when passed host, user" do
76
+ it "tries to connect to the passed host" do
77
+ @ftp.should_receive(:connect).with("localhost")
78
+ @ftp.send(:initialize, "localhost")
79
+ end
80
+
81
+ it "tries to login with the passed username, password and account" do
82
+ @ftp.should_receive(:login).with("rubyspec", "rocks", "account")
83
+ @ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account")
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../shared/last_response_code', __FILE__)
3
+ require File.expand_path('../fixtures/server', __FILE__)
4
+
5
+ describe "Net::FTP#last_response_code" do
6
+ it_behaves_like :net_ftp_last_response_code, :last_response_code
7
+ end
@@ -0,0 +1,24 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#last_response" 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 "returns the last response" do
20
+ @ftp.last_response.should == "220 Dummy FTP Server ready!\n"
21
+ @ftp.help
22
+ @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../shared/last_response_code', __FILE__)
3
+ require File.expand_path('../fixtures/server', __FILE__)
4
+
5
+ describe "Net::FTP#lastresp" do
6
+ it_behaves_like :net_ftp_last_response_code, :lastresp
7
+ end
data/spec/list_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+ require File.expand_path('../shared/list', __FILE__)
4
+
5
+ describe "Net::FTP#list" do
6
+ it_behaves_like :net_ftp_list, :list
7
+ end
@@ -0,0 +1,215 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#login" 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 passed no arguments" do
20
+ it "sends the USER command with 'anonymous' as name to the server" do
21
+ @ftp.login
22
+ @server.login_user.should == "anonymous"
23
+ end
24
+
25
+ ruby_version_is "" ... "1.9" do
26
+ it "sends the current username + hostname as a password when required" do
27
+ passhost = Socket.gethostname
28
+ if not passhost.index(".")
29
+ passhost = Socket.gethostbyname(passhost)[0]
30
+ end
31
+ pass = ENV["USER"] + "@" + passhost
32
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
33
+ @ftp.login
34
+ @server.login_pass.should == pass
35
+ end
36
+ end
37
+
38
+ ruby_version_is "1.9" do
39
+ it "sends 'anonymous@' as a password when required" do
40
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
41
+ @ftp.login
42
+ @server.login_pass.should == "anonymous@"
43
+ end
44
+ end
45
+
46
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/385", "1.8.7" do
47
+ it "raises a Net::FTPReplyError when the server requests an account" do
48
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
49
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
50
+ lambda { @ftp.login }.should raise_error(Net::FTPReplyError)
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "when passed name" do
56
+ it "sends the USER command with the passed name to the server" do
57
+ @ftp.login("rubyspec")
58
+ @server.login_user.should == "rubyspec"
59
+ end
60
+
61
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/385", "1.8.7" do
62
+ it "raises a Net::FTPReplyError when the server requests a password, but none was given" do
63
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
64
+ lambda { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError)
65
+ end
66
+
67
+ it "raises a Net::FTPReplyError when the server requests an account, but none was given" do
68
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
69
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
70
+ lambda { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError)
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "when passed name, password" do
76
+ it "sends the USER command with the passed name to the server" do
77
+ @ftp.login("rubyspec", "rocks")
78
+ @server.login_user.should == "rubyspec"
79
+ end
80
+
81
+ it "sends the passed password when required" do
82
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
83
+ @ftp.login("rubyspec", "rocks")
84
+ @server.login_pass.should == "rocks"
85
+ end
86
+
87
+ ruby_bug "http://redmine.ruby-lang.org/issues/show/385", "1.8.7" do
88
+ it "raises a Net::FTPReplyError when the server requests an account" do
89
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
90
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
91
+ lambda { @ftp.login("rubyspec", "rocks") }.should raise_error(Net::FTPReplyError)
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "when passed name, password, account" do
97
+ it "sends the USER command with the passed name to the server" do
98
+ @ftp.login("rubyspec", "rocks", "account")
99
+ @server.login_user.should == "rubyspec"
100
+ end
101
+
102
+ it "sends the passed password when required" do
103
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
104
+ @ftp.login("rubyspec", "rocks", "account")
105
+ @server.login_pass.should == "rocks"
106
+ end
107
+
108
+ it "sends the passed account when required" do
109
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
110
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
111
+ @ftp.login("rubyspec", "rocks", "account")
112
+ @server.login_acct.should == "account"
113
+ end
114
+ end
115
+
116
+ describe "when the USER command fails" do
117
+ it "raises a Net::FTPPermError when the response code is 500" do
118
+ @server.should_receive(:user).and_respond("500 Syntax error, command unrecognized.")
119
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
120
+ end
121
+
122
+ it "raises a Net::FTPPermError when the response code is 501" do
123
+ @server.should_receive(:user).and_respond("501 Syntax error in parameters or arguments.")
124
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
125
+ end
126
+
127
+ it "raises a Net::FTPPermError when the response code is 502" do
128
+ @server.should_receive(:user).and_respond("502 Command not implemented.")
129
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
130
+ end
131
+
132
+ it "raises a Net::FTPTempError when the response code is 421" do
133
+ @server.should_receive(:user).and_respond("421 Service not available, closing control connection.")
134
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
135
+ end
136
+
137
+ it "raises a Net::FTPPermError when the response code is 530" do
138
+ @server.should_receive(:user).and_respond("530 Not logged in.")
139
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
140
+ end
141
+ end
142
+
143
+ describe "when the PASS command fails" do
144
+ before(:each) do
145
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
146
+ end
147
+
148
+ it "does not raise an Error when the response code is 202" do
149
+ @server.should_receive(:pass).and_respond("202 Command not implemented, superfluous at this site.")
150
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error
151
+ end
152
+
153
+ it "raises a Net::FTPPermError when the response code is 500" do
154
+ @server.should_receive(:pass).and_respond("500 Syntax error, command unrecognized.")
155
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
156
+ end
157
+
158
+ it "raises a Net::FTPPermError when the response code is 501" do
159
+ @server.should_receive(:pass).and_respond("501 Syntax error in parameters or arguments.")
160
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
161
+ end
162
+
163
+ it "raises a Net::FTPPermError when the response code is 502" do
164
+ @server.should_receive(:pass).and_respond("502 Command not implemented.")
165
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
166
+ end
167
+
168
+ it "raises a Net::FTPTempError when the response code is 421" do
169
+ @server.should_receive(:pass).and_respond("421 Service not available, closing control connection.")
170
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
171
+ end
172
+
173
+ it "raises a Net::FTPPermError when the response code is 530" do
174
+ @server.should_receive(:pass).and_respond("530 Not logged in.")
175
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
176
+ end
177
+ end
178
+
179
+ describe "when the ACCT command fails" do
180
+ before(:each) do
181
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
182
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
183
+ end
184
+
185
+ it "does not raise an Error when the response code is 202" do
186
+ @server.should_receive(:acct).and_respond("202 Command not implemented, superfluous at this site.")
187
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error
188
+ end
189
+
190
+ it "raises a Net::FTPPermError when the response code is 500" do
191
+ @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
192
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
193
+ end
194
+
195
+ it "raises a Net::FTPPermError when the response code is 501" do
196
+ @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
197
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
198
+ end
199
+
200
+ it "raises a Net::FTPPermError when the response code is 502" do
201
+ @server.should_receive(:acct).and_respond("502 Command not implemented.")
202
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
203
+ end
204
+
205
+ it "raises a Net::FTPTempError when the response code is 421" do
206
+ @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
207
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
208
+ end
209
+
210
+ it "raises a Net::FTPPermError when the response code is 530" do
211
+ @server.should_receive(:acct).and_respond("530 Not logged in.")
212
+ lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
213
+ end
214
+ end
215
+ end
data/spec/ls_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+ require File.expand_path('../shared/list', __FILE__)
4
+
5
+ describe "Net::FTP#ls" do
6
+ it_behaves_like :net_ftp_list, :ls
7
+ end
data/spec/mdtm_spec.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#mdtm" 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 MDTM with the passed filename command to the server" do
20
+ @ftp.mdtm("test.file")
21
+ @ftp.last_response.should == "213 19980705132316\n"
22
+ end
23
+
24
+ it "returns the last modification time of the passed file" do
25
+ @ftp.mdtm("test.file").should == "19980705132316"
26
+ end
27
+
28
+ it "raises a Net::FTPPermError when the response code is 550" do
29
+ @server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
30
+ lambda { @ftp.mdtm("test.file") }.should raise_error(Net::FTPPermError)
31
+ end
32
+
33
+ it "raises a Net::FTPTempError when the response code is 421" do
34
+ @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
35
+ lambda { @ftp.mdtm("test.file") }.should raise_error(Net::FTPTempError)
36
+ end
37
+ end
@@ -0,0 +1,60 @@
1
+ require 'net/ftp'
2
+ require File.expand_path('../fixtures/server', __FILE__)
3
+
4
+ describe "Net::FTP#mkdir" 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 MKD command with the passed pathname to the server" do
20
+ @ftp.mkdir("test.folder")
21
+ @ftp.last_response.should == %{257 "test.folder" created.\n}
22
+ end
23
+
24
+ it "returns the path to the newly created directory" do
25
+ @ftp.mkdir("test.folder").should == "test.folder"
26
+ @ftp.mkdir("/absolute/path/to/test.folder").should == "/absolute/path/to/test.folder"
27
+ @ftp.mkdir("relative/path/to/test.folder").should == "relative/path/to/test.folder"
28
+ @ftp.mkdir('/usr/dm/foo"bar').should == '/usr/dm/foo"bar'
29
+ end
30
+
31
+ it "raises a Net::FTPPermError when the response code is 500" do
32
+ @server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.")
33
+ lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
34
+ end
35
+
36
+ it "raises a Net::FTPPermError when the response code is 501" do
37
+ @server.should_receive(:mkd).and_respond("501 Syntax error in parameters or arguments.")
38
+ lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
39
+ end
40
+
41
+ it "raises a Net::FTPPermError when the response code is 502" do
42
+ @server.should_receive(:mkd).and_respond("502 Command not implemented.")
43
+ lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
44
+ end
45
+
46
+ it "raises a Net::FTPTempError when the response code is 421" do
47
+ @server.should_receive(:mkd).and_respond("421 Service not available, closing control connection.")
48
+ lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPTempError)
49
+ end
50
+
51
+ it "raises a Net::FTPPermError when the response code is 530" do
52
+ @server.should_receive(:mkd).and_respond("530 Not logged in.")
53
+ lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
54
+ end
55
+
56
+ it "raises a Net::FTPPermError when the response code is 550" do
57
+ @server.should_receive(:mkd).and_respond("550 Requested action not taken.")
58
+ lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
59
+ end
60
+ end