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,25 @@
1
+ describe :net_ftp_last_response_code, :shared => true do
2
+ before(:each) do
3
+ @server = NetFTPSpecs::DummyFTP.new
4
+ @server.serve_once
5
+
6
+ @ftp = Net::FTP.new
7
+ @ftp.connect("localhost", 9921)
8
+ end
9
+
10
+ after(:each) do
11
+ @ftp.quit rescue nil
12
+ @ftp.close
13
+ @server.stop
14
+ end
15
+
16
+ it "returns the response code for the last response" do
17
+ @server.should_receive(:help).and_respond("200 Command okay.")
18
+ @ftp.help
19
+ @ftp.send(@method).should == "200"
20
+
21
+ @server.should_receive(:help).and_respond("212 Directory status.")
22
+ @ftp.help
23
+ @ftp.send(@method).should == "212"
24
+ end
25
+ end
@@ -0,0 +1,133 @@
1
+ describe :net_ftp_list, :shared => true do
2
+ before(:each) do
3
+ @server = NetFTPSpecs::DummyFTP.new
4
+ @server.serve_once
5
+
6
+ @ftp = Net::FTP.new
7
+ @ftp.passive = false
8
+ @ftp.connect("localhost", 9921)
9
+ end
10
+
11
+ after(:each) do
12
+ @ftp.quit rescue nil
13
+ @ftp.close
14
+ @server.stop
15
+ end
16
+
17
+ describe "when passed a block" do
18
+ it "yields each file in the list of files in the passed dir" do
19
+ expected = [
20
+ "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
21
+ "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
22
+ "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
23
+ ]
24
+
25
+ res = []
26
+ @ftp.send(@method, "test.folder") { |line| res << line}
27
+ res.should == expected
28
+
29
+ @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
30
+ end
31
+ end
32
+
33
+ describe "when passed no block" do
34
+ it "returns an Array containing a list of files in the passed dir" do
35
+ expected = [
36
+ "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
37
+ "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
38
+ "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
39
+ ]
40
+
41
+ @ftp.send(@method, "test.folder").should == expected
42
+
43
+ @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
44
+ end
45
+ end
46
+
47
+ describe "when the LIST command fails" do
48
+ it "raises a Net::FTPTempError when the response code is 450" do
49
+ @server.should_receive(:list).and_respond("450 Requested file action not taken..")
50
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
51
+ end
52
+
53
+ it "raises a Net::FTPPermError when the response code is 500" do
54
+ @server.should_receive(:list).and_respond("500 Syntax error, command unrecognized.")
55
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
56
+ end
57
+
58
+ it "raises a Net::FTPPermError when the response code is 501" do
59
+ @server.should_receive(:list).and_respond("501 Syntax error, command unrecognized.")
60
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
61
+ end
62
+
63
+ it "raises a Net::FTPPermError when the response code is 502" do
64
+ @server.should_receive(:list).and_respond("502 Command not implemented.")
65
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
66
+ end
67
+
68
+ it "raises a Net::FTPTempError when the response code is 421" do
69
+ @server.should_receive(:list).and_respond("421 Service not available, closing control connection.")
70
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
71
+ end
72
+
73
+ it "raises a Net::FTPPermError when the response code is 530" do
74
+ @server.should_receive(:list).and_respond("530 Not logged in.")
75
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
76
+ end
77
+ end
78
+
79
+ ruby_version_is "" ... "1.9" do
80
+ describe "when switching type fails" do
81
+ it "raises a Net::FTPPermError when the response code is 500" do
82
+ @server.should_receive(:type).and_respond("500 Syntax error, command unrecognized.")
83
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
84
+ end
85
+
86
+ it "raises a Net::FTPPermError when the response code is 501" do
87
+ @server.should_receive(:type).and_respond("501 Syntax error in parameters or arguments.")
88
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
89
+ end
90
+
91
+ it "raises a Net::FTPPermError when the response code is 504" do
92
+ @server.should_receive(:type).and_respond("504 Command not implemented for that parameter.")
93
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
94
+ end
95
+
96
+ it "raises a Net::FTPTempError when the response code is 421" do
97
+ @server.should_receive(:type).and_respond("421 Service not available, closing control connection.")
98
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
99
+ end
100
+
101
+ it "raises a Net::FTPPermError when the response code is 530" do
102
+ @server.should_receive(:type).and_respond("530 Not logged in.")
103
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
104
+ end
105
+ end
106
+ end
107
+
108
+ describe "when opening the data port fails" do
109
+ it "raises a Net::FTPPermError when the response code is 500" do
110
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
111
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
112
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
113
+ end
114
+
115
+ it "raises a Net::FTPPermError when the response code is 501" do
116
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
117
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
118
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
119
+ end
120
+
121
+ it "raises a Net::FTPTempError when the response code is 421" do
122
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
123
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
124
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
125
+ end
126
+
127
+ it "raises a Net::FTPPermError when the response code is 530" do
128
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
129
+ @server.should_receive(:port).and_respond("530 Not logged in.")
130
+ lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,232 @@
1
+ describe :net_ftp_putbinaryfile, :shared => true do
2
+ before(:each) do
3
+ @server = NetFTPSpecs::DummyFTP.new
4
+ @server.serve_once
5
+
6
+ @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/putbinaryfile"
7
+ @remote_tmp_file = tmp("binaryfile", false)
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ @ftp.binary = @binary_mode
12
+ end
13
+
14
+ after(:each) do
15
+ @ftp.quit rescue nil
16
+ @ftp.close
17
+ @server.stop
18
+
19
+ rm_r @remote_tmp_file
20
+ end
21
+
22
+ it "sends the STOR command to the server" do
23
+ @ftp.send(@method, @local_fixture_file, "binary")
24
+ @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
25
+ end
26
+
27
+ it "sends the contents of the passed local_file, without modifications" do
28
+ @ftp.send(@method, @local_fixture_file, "binary")
29
+
30
+ remote_lines = File.readlines(@remote_tmp_file)
31
+ local_lines = File.readlines(@local_fixture_file)
32
+
33
+ remote_lines.should == local_lines
34
+ end
35
+
36
+ it "returns nil" do
37
+ @ftp.send(@method, @local_fixture_file, "binary").should be_nil
38
+ end
39
+
40
+ describe "when passed a block" do
41
+ it "yields the transmitted content as binary blocks of the passed size" do
42
+ res = []
43
+ @ftp.send(@method, @local_fixture_file, "binary", 10) { |x| res << x }
44
+ res.should == [
45
+ "This is an", " example f",
46
+ "ile\nwhich ", "is going t",
47
+ "o be trans", "mitted\nusi",
48
+ "ng #putbin", "aryfile."
49
+ ]
50
+ end
51
+ end
52
+
53
+ describe "when resuming an existing file" do
54
+ before(:each) do
55
+ File.open(@remote_tmp_file, "w") do |f|
56
+ f << "This is an example file\n"
57
+ end
58
+
59
+ @ftp.resume = true
60
+ end
61
+
62
+ it "sends the remaining content of the passed local_file to the passed remote_file" do
63
+ @ftp.send(@method, @local_fixture_file, "binary")
64
+ File.read(@remote_tmp_file).should == File.read(@local_fixture_file)
65
+ end
66
+
67
+ ruby_version_is "" ... "1.9" do
68
+ describe "and the REST command fails" do
69
+ it "raises a Net::FTPProtoError when the response code is 550" do
70
+ @server.should_receive(:rest).and_respond("Requested action not taken.")
71
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPProtoError)
72
+ end
73
+
74
+ it "raises a Net::FTPPermError when the response code is 500" do
75
+ @server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.")
76
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
77
+ end
78
+
79
+ it "raises a Net::FTPPermError when the response code is 501" do
80
+ @server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.")
81
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
82
+ end
83
+
84
+ it "raises a Net::FTPPermError when the response code is 502" do
85
+ @server.should_receive(:rest).and_respond("502 Command not implemented.")
86
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
87
+ end
88
+
89
+ it "raises a Net::FTPTempError when the response code is 421" do
90
+ @server.should_receive(:rest).and_respond("421 Service not available, closing control connection.")
91
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
92
+ end
93
+
94
+ it "raises a Net::FTPPermError when the response code is 530" do
95
+ @server.should_receive(:rest).and_respond("530 Not logged in.")
96
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
97
+ end
98
+ end
99
+ end
100
+
101
+ ruby_version_is "1.9" do
102
+ describe "and the APPE command fails" do
103
+ it "raises a Net::FTPProtoError when the response code is 550" do
104
+ @server.should_receive(:appe).and_respond("Requested action not taken.")
105
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPProtoError)
106
+ end
107
+
108
+ it "raises a Net::FTPPermError when the response code is 500" do
109
+ @server.should_receive(:appe).and_respond("500 Syntax error, command unrecognized.")
110
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
111
+ end
112
+
113
+ it "raises a Net::FTPPermError when the response code is 501" do
114
+ @server.should_receive(:appe).and_respond("501 Syntax error, command unrecognized.")
115
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
116
+ end
117
+
118
+ it "raises a Net::FTPPermError when the response code is 502" do
119
+ @server.should_receive(:appe).and_respond("502 Command not implemented.")
120
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
121
+ end
122
+
123
+ it "raises a Net::FTPTempError when the response code is 421" do
124
+ @server.should_receive(:appe).and_respond("421 Service not available, closing control connection.")
125
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
126
+ end
127
+
128
+ it "raises a Net::FTPPermError when the response code is 530" do
129
+ @server.should_receive(:appe).and_respond("530 Not logged in.")
130
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
131
+ end
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "when the STOR command fails" do
137
+ it "raises a Net::FTPPermError when the response code is 532" do
138
+ @server.should_receive(:stor).and_respond("532 Need account for storing files.")
139
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
140
+ end
141
+
142
+ it "raises a Net::FTPTempError when the response code is 450" do
143
+ @server.should_receive(:stor).and_respond("450 Requested file action not taken.")
144
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
145
+ end
146
+
147
+ it "raises a Net::FTPTempError when the response code is 452" do
148
+ @server.should_receive(:stor).and_respond("452 Requested action not taken.")
149
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
150
+ end
151
+
152
+ it "raises a Net::FTPPermError when the response code is 553" do
153
+ @server.should_receive(:stor).and_respond("553 Requested action not taken.")
154
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
155
+ end
156
+
157
+ it "raises a Net::FTPPermError when the response code is 500" do
158
+ @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
159
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
160
+ end
161
+
162
+ it "raises a Net::FTPPermError when the response code is 501" do
163
+ @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
164
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
165
+ end
166
+
167
+ it "raises a Net::FTPTempError when the response code is 421" do
168
+ @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
169
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
170
+ end
171
+
172
+ it "raises a Net::FTPPermError when the response code is 530" do
173
+ @server.should_receive(:stor).and_respond("530 Not logged in.")
174
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
175
+ end
176
+ end
177
+
178
+ ruby_version_is "" ... "1.9" do
179
+ describe "when switching type fails" do
180
+ it "raises a Net::FTPPermError when the response code is 500" do
181
+ @server.should_receive(:type).and_respond("500 Syntax error, command unrecognized.")
182
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
183
+ end
184
+
185
+ it "raises a Net::FTPPermError when the response code is 501" do
186
+ @server.should_receive(:type).and_respond("501 Syntax error in parameters or arguments.")
187
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
188
+ end
189
+
190
+ it "raises a Net::FTPPermError when the response code is 504" do
191
+ @server.should_receive(:type).and_respond("504 Command not implemented for that parameter.")
192
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
193
+ end
194
+
195
+ it "raises a Net::FTPTempError when the response code is 421" do
196
+ @server.should_receive(:type).and_respond("421 Service not available, closing control connection.")
197
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
198
+ end
199
+
200
+ it "raises a Net::FTPPermError when the response code is 530" do
201
+ @server.should_receive(:type).and_respond("530 Not logged in.")
202
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
203
+ end
204
+ end
205
+ end
206
+
207
+ describe "when opening the data port fails" do
208
+ it "raises a Net::FTPPermError when the response code is 500" do
209
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
210
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
211
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
212
+ end
213
+
214
+ it "raises a Net::FTPPermError when the response code is 501" do
215
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
216
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
217
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
218
+ end
219
+
220
+ it "raises a Net::FTPTempError when the response code is 421" do
221
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
222
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
223
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
224
+ end
225
+
226
+ it "raises a Net::FTPPermError when the response code is 530" do
227
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
228
+ @server.should_receive(:port).and_respond("530 Not logged in.")
229
+ lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
230
+ end
231
+ end
232
+ end
@@ -0,0 +1,149 @@
1
+ describe :net_ftp_puttextfile, :shared => true do
2
+ before(:each) do
3
+ @server = NetFTPSpecs::DummyFTP.new
4
+ @server.serve_once
5
+
6
+ @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/puttextfile"
7
+ @remote_tmp_file = tmp("textfile", false)
8
+
9
+ @ftp = Net::FTP.new
10
+ @ftp.connect("localhost", 9921)
11
+ @ftp.binary = @binary_mode
12
+ end
13
+
14
+ after(:each) do
15
+ @ftp.quit rescue nil
16
+ @ftp.close
17
+ @server.stop
18
+
19
+ rm_r @remote_tmp_file
20
+ end
21
+
22
+ it "sends the STOR command to the server" do
23
+ @ftp.send(@method, @local_fixture_file, "text")
24
+ @ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
25
+ end
26
+
27
+ it "sends the contents of the passed local_file, using \\r\\n as the newline separator" do
28
+ @ftp.send(@method, @local_fixture_file, "text")
29
+
30
+ remote_lines = open(@remote_tmp_file, "rb") {|f| f.read }
31
+ local_lines = open(@local_fixture_file, "rb") {|f| f.read } + "\n"
32
+
33
+ remote_lines.should_not == local_lines
34
+ remote_lines.should == local_lines.gsub("\n", "\r\n")
35
+ end
36
+
37
+ it "returns nil" do
38
+ @ftp.send(@method, @local_fixture_file, "text").should be_nil
39
+ end
40
+
41
+ describe "when passed a block" do
42
+ it "yields each transmitted line" do
43
+ res = []
44
+ @ftp.send(@method, @local_fixture_file, "text") { |x| res << x }
45
+ res.should == [
46
+ "This is an example file\r\n",
47
+ "which is going to be transmitted\r\n",
48
+ "using #puttextfile.\r\n"
49
+ ]
50
+ end
51
+ end
52
+
53
+ describe "when the STOR command fails" do
54
+ it "raises a Net::FTPPermError when the response code is 532" do
55
+ @server.should_receive(:stor).and_respond("532 Need account for storing files.")
56
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
57
+ end
58
+
59
+ it "raises a Net::FTPTempError when the response code is 450" do
60
+ @server.should_receive(:stor).and_respond("450 Requested file action not taken.")
61
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
62
+ end
63
+
64
+ it "raises a Net::FTPTempError when the response code is 452" do
65
+ @server.should_receive(:stor).and_respond("452 Requested action not taken.")
66
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
67
+ end
68
+
69
+ it "raises a Net::FTPPermError when the response code is 553" do
70
+ @server.should_receive(:stor).and_respond("553 Requested action not taken.")
71
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
72
+ end
73
+
74
+ it "raises a Net::FTPPermError when the response code is 500" do
75
+ @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
76
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
77
+ end
78
+
79
+ it "raises a Net::FTPPermError when the response code is 501" do
80
+ @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
81
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
82
+ end
83
+
84
+ it "raises a Net::FTPTempError when the response code is 421" do
85
+ @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
86
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
87
+ end
88
+
89
+ it "raises a Net::FTPPermError when the response code is 530" do
90
+ @server.should_receive(:stor).and_respond("530 Not logged in.")
91
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
92
+ end
93
+ end
94
+
95
+ ruby_version_is "" ... "1.9" do
96
+ describe "when switching type fails" do
97
+ it "raises a Net::FTPPermError when the response code is 500" do
98
+ @server.should_receive(:type).and_respond("500 Syntax error, command unrecognized.")
99
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
100
+ end
101
+
102
+ it "raises a Net::FTPPermError when the response code is 501" do
103
+ @server.should_receive(:type).and_respond("501 Syntax error in parameters or arguments.")
104
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
105
+ end
106
+
107
+ it "raises a Net::FTPPermError when the response code is 504" do
108
+ @server.should_receive(:type).and_respond("504 Command not implemented for that parameter.")
109
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
110
+ end
111
+
112
+ it "raises a Net::FTPTempError when the response code is 421" do
113
+ @server.should_receive(:type).and_respond("421 Service not available, closing control connection.")
114
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
115
+ end
116
+
117
+ it "raises a Net::FTPPermError when the response code is 530" do
118
+ @server.should_receive(:type).and_respond("530 Not logged in.")
119
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
120
+ end
121
+ end
122
+ end
123
+
124
+ describe "when opening the data port fails" do
125
+ it "raises a Net::FTPPermError when the response code is 500" do
126
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
127
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
128
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
129
+ end
130
+
131
+ it "raises a Net::FTPPermError when the response code is 501" do
132
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
133
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
134
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
135
+ end
136
+
137
+ it "raises a Net::FTPTempError when the response code is 421" do
138
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
139
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
140
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
141
+ end
142
+
143
+ it "raises a Net::FTPPermError when the response code is 530" do
144
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
145
+ @server.should_receive(:port).and_respond("530 Not logged in.")
146
+ lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
147
+ end
148
+ end
149
+ end