net-sftp 2.0.5 → 3.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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data/.gitignore +5 -0
- data/.travis.yml +20 -0
- data/{CHANGELOG.rdoc → CHANGES.txt} +18 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +19 -0
- data/README.rdoc +23 -1
- data/Rakefile +44 -21
- data/lib/net/sftp/operations/dir.rb +3 -3
- data/lib/net/sftp/operations/download.rb +8 -7
- data/lib/net/sftp/operations/file.rb +30 -8
- data/lib/net/sftp/operations/upload.rb +14 -6
- data/lib/net/sftp/session.rb +9 -7
- data/lib/net/sftp/version.rb +63 -13
- data/lib/net/sftp.rb +12 -4
- data/net-sftp-public_cert.pem +20 -0
- data/net-sftp.gemspec +38 -24
- data.tar.gz.sig +0 -0
- metadata +110 -127
- metadata.gz.sig +0 -0
- data/test/common.rb +0 -172
- data/test/protocol/01/test_attributes.rb +0 -97
- data/test/protocol/01/test_base.rb +0 -210
- data/test/protocol/01/test_name.rb +0 -27
- data/test/protocol/02/test_base.rb +0 -26
- data/test/protocol/03/test_base.rb +0 -27
- data/test/protocol/04/test_attributes.rb +0 -148
- data/test/protocol/04/test_base.rb +0 -74
- data/test/protocol/04/test_name.rb +0 -53
- data/test/protocol/05/test_base.rb +0 -62
- data/test/protocol/06/test_attributes.rb +0 -124
- data/test/protocol/06/test_base.rb +0 -51
- data/test/protocol/test_base.rb +0 -42
- data/test/test_all.rb +0 -7
- data/test/test_dir.rb +0 -47
- data/test/test_download.rb +0 -252
- data/test/test_file.rb +0 -159
- data/test/test_file_factory.rb +0 -48
- data/test/test_packet.rb +0 -9
- data/test/test_protocol.rb +0 -17
- data/test/test_request.rb +0 -71
- data/test/test_response.rb +0 -53
- data/test/test_session.rb +0 -741
- data/test/test_upload.rb +0 -219
data/test/test_upload.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
require "common"
|
2
|
-
|
3
|
-
class UploadTest < Net::SFTP::TestCase
|
4
|
-
def setup
|
5
|
-
prepare_progress!
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_upload_file_should_send_file_contents
|
9
|
-
expect_file_transfer("/path/to/local", "/path/to/remote", "here are the contents")
|
10
|
-
assert_scripted_command { sftp.upload("/path/to/local", "/path/to/remote") }
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_upload_file_with_progress_should_report_progress
|
14
|
-
expect_file_transfer("/path/to/local", "/path/to/remote", "here are the contents")
|
15
|
-
|
16
|
-
assert_scripted_command do
|
17
|
-
sftp.upload("/path/to/local", "/path/to/remote") { |*args| record_progress(args) }
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_progress_reported_open(:remote => "/path/to/remote")
|
21
|
-
assert_progress_reported_put(0, "here are the contents", :remote => "/path/to/remote")
|
22
|
-
assert_progress_reported_close(:remote => "/path/to/remote")
|
23
|
-
assert_progress_reported_finish
|
24
|
-
assert_no_more_reported_events
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_upload_file_with_progress_handler_should_report_progress
|
28
|
-
expect_file_transfer("/path/to/local", "/path/to/remote", "here are the contents")
|
29
|
-
|
30
|
-
assert_scripted_command do
|
31
|
-
sftp.upload("/path/to/local", "/path/to/remote", :progress => ProgressHandler.new(@progress))
|
32
|
-
end
|
33
|
-
|
34
|
-
assert_progress_reported_open(:remote => "/path/to/remote")
|
35
|
-
assert_progress_reported_put(0, "here are the contents", :remote => "/path/to/remote")
|
36
|
-
assert_progress_reported_close(:remote => "/path/to/remote")
|
37
|
-
assert_progress_reported_finish
|
38
|
-
assert_no_more_reported_events
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_upload_file_should_read_chunks_of_size(requested_size=nil)
|
42
|
-
size = requested_size || Net::SFTP::Operations::Upload::DEFAULT_READ_SIZE
|
43
|
-
expect_sftp_session :server_version => 3 do |channel|
|
44
|
-
channel.sends_packet(FXP_OPEN, :long, 0, :string, "/path/to/remote", :long, 0x1A, :long, 0)
|
45
|
-
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
|
46
|
-
channel.sends_packet(FXP_WRITE, :long, 1, :string, "handle", :int64, 0, :string, "a" * size)
|
47
|
-
channel.sends_packet(FXP_WRITE, :long, 2, :string, "handle", :int64, size, :string, "b" * size)
|
48
|
-
channel.sends_packet(FXP_WRITE, :long, 3, :string, "handle", :int64, size*2, :string, "c" * size)
|
49
|
-
channel.gets_packet(FXP_STATUS, :long, 1, :long, 0)
|
50
|
-
channel.sends_packet(FXP_WRITE, :long, 4, :string, "handle", :int64, size*3, :string, "d" * size)
|
51
|
-
channel.gets_packet(FXP_STATUS, :long, 2, :long, 0)
|
52
|
-
channel.sends_packet(FXP_CLOSE, :long, 5, :string, "handle")
|
53
|
-
channel.gets_packet(FXP_STATUS, :long, 3, :long, 0)
|
54
|
-
channel.gets_packet(FXP_STATUS, :long, 4, :long, 0)
|
55
|
-
channel.gets_packet(FXP_STATUS, :long, 5, :long, 0)
|
56
|
-
end
|
57
|
-
|
58
|
-
expect_file("/path/to/local", "a" * size + "b" * size + "c" * size + "d" * size)
|
59
|
-
|
60
|
-
assert_scripted_command do
|
61
|
-
opts = {}
|
62
|
-
opts[:read_size] = size if requested_size
|
63
|
-
sftp.upload("/path/to/local", "/path/to/remote", opts)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_upload_file_with_custom_read_size_should_read_chunks_of_that_size
|
68
|
-
test_upload_file_should_read_chunks_of_size(100)
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_upload_file_with_custom_requests_should_start_that_many_writes
|
72
|
-
size = Net::SFTP::Operations::Upload::DEFAULT_READ_SIZE
|
73
|
-
expect_sftp_session :server_version => 3 do |channel|
|
74
|
-
channel.sends_packet(FXP_OPEN, :long, 0, :string, "/path/to/remote", :long, 0x1A, :long, 0)
|
75
|
-
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
|
76
|
-
channel.sends_packet(FXP_WRITE, :long, 1, :string, "handle", :int64, 0, :string, "a" * size)
|
77
|
-
channel.sends_packet(FXP_WRITE, :long, 2, :string, "handle", :int64, size, :string, "b" * size)
|
78
|
-
channel.sends_packet(FXP_WRITE, :long, 3, :string, "handle", :int64, size*2, :string, "c" * size)
|
79
|
-
channel.sends_packet(FXP_WRITE, :long, 4, :string, "handle", :int64, size*3, :string, "d" * size)
|
80
|
-
channel.gets_packet(FXP_STATUS, :long, 1, :long, 0)
|
81
|
-
channel.sends_packet(FXP_CLOSE, :long, 5, :string, "handle")
|
82
|
-
channel.gets_packet(FXP_STATUS, :long, 2, :long, 0)
|
83
|
-
channel.gets_packet(FXP_STATUS, :long, 3, :long, 0)
|
84
|
-
channel.gets_packet(FXP_STATUS, :long, 4, :long, 0)
|
85
|
-
channel.gets_packet(FXP_STATUS, :long, 5, :long, 0)
|
86
|
-
end
|
87
|
-
|
88
|
-
expect_file("/path/to/local", "a" * size + "b" * size + "c" * size + "d" * size)
|
89
|
-
|
90
|
-
assert_scripted_command do
|
91
|
-
sftp.upload("/path/to/local", "/path/to/remote", :requests => 3)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_upload_directory_should_mirror_directory_structure_remotely
|
96
|
-
prepare_directory
|
97
|
-
|
98
|
-
assert_scripted_command do
|
99
|
-
sftp.upload("/path/to/local", "/path/to/remote")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_upload_directory_with_handler_should_report_progress
|
104
|
-
prepare_directory
|
105
|
-
|
106
|
-
assert_scripted_command do
|
107
|
-
sftp.upload("/path/to/local", "/path/to/remote") { |*args| record_progress(args) }
|
108
|
-
end
|
109
|
-
|
110
|
-
assert_progress_reported_open(:remote => "/path/to/remote/file1")
|
111
|
-
assert_progress_reported_open(:remote => "/path/to/remote/file2")
|
112
|
-
assert_progress_reported_open(:remote => "/path/to/remote/file3")
|
113
|
-
assert_progress_reported_mkdir("/path/to/remote/subdir")
|
114
|
-
assert_progress_reported_open(:remote => "/path/to/remote/subdir/other1")
|
115
|
-
assert_progress_reported_open(:remote => "/path/to/remote/subdir/other2")
|
116
|
-
assert_progress_reported_put(0, "contents of file1", :remote => "/path/to/remote/file1")
|
117
|
-
assert_progress_reported_put(0, "contents of file2", :remote => "/path/to/remote/file2")
|
118
|
-
assert_progress_reported_put(0, "contents of file3", :remote => "/path/to/remote/file3")
|
119
|
-
assert_progress_reported_close(:remote => "/path/to/remote/file1")
|
120
|
-
assert_progress_reported_put(0, "contents of other1", :remote => "/path/to/remote/subdir/other1")
|
121
|
-
assert_progress_reported_put(0, "contents of other2", :remote => "/path/to/remote/subdir/other2")
|
122
|
-
assert_progress_reported_close(:remote => "/path/to/remote/file2")
|
123
|
-
assert_progress_reported_close(:remote => "/path/to/remote/file3")
|
124
|
-
assert_progress_reported_close(:remote => "/path/to/remote/subdir/other1")
|
125
|
-
assert_progress_reported_close(:remote => "/path/to/remote/subdir/other2")
|
126
|
-
assert_progress_reported_finish
|
127
|
-
assert_no_more_reported_events
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_upload_io_should_send_io_as_file
|
131
|
-
expect_sftp_session :server_version => 3 do |channel|
|
132
|
-
channel.sends_packet(FXP_OPEN, :long, 0, :string, "/path/to/remote", :long, 0x1A, :long, 0)
|
133
|
-
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
|
134
|
-
channel.sends_packet(FXP_WRITE, :long, 1, :string, "handle", :int64, 0, :string, "this is some text")
|
135
|
-
channel.sends_packet(FXP_CLOSE, :long, 2, :string, "handle")
|
136
|
-
channel.gets_packet(FXP_STATUS, :long, 1, :long, 0)
|
137
|
-
channel.gets_packet(FXP_STATUS, :long, 2, :long, 0)
|
138
|
-
end
|
139
|
-
|
140
|
-
assert_scripted_command do
|
141
|
-
sftp.upload(StringIO.new("this is some text"), "/path/to/remote")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
private
|
146
|
-
|
147
|
-
def prepare_directory
|
148
|
-
expect_directory("/path/to/local", %w(. .. file1 file2 file3 subdir))
|
149
|
-
expect_directory("/path/to/local/subdir", %w(. .. other1 other2))
|
150
|
-
expect_file("/path/to/local/file1", "contents of file1")
|
151
|
-
expect_file("/path/to/local/file2", "contents of file2")
|
152
|
-
expect_file("/path/to/local/file3", "contents of file3")
|
153
|
-
expect_file("/path/to/local/subdir/other1", "contents of other1")
|
154
|
-
expect_file("/path/to/local/subdir/other2", "contents of other2")
|
155
|
-
|
156
|
-
expect_sftp_session :server_version => 3 do |ch|
|
157
|
-
ch.sends_packet(FXP_MKDIR, :long, 0, :string, "/path/to/remote", :long, 0)
|
158
|
-
ch.gets_packet(FXP_STATUS, :long, 0, :long, 0)
|
159
|
-
ch.sends_packet(FXP_OPEN, :long, 1, :string, "/path/to/remote/file1", :long, 0x1A, :long, 0)
|
160
|
-
ch.sends_packet(FXP_OPEN, :long, 2, :string, "/path/to/remote/file2", :long, 0x1A, :long, 0)
|
161
|
-
ch.sends_packet(FXP_OPEN, :long, 3, :string, "/path/to/remote/file3", :long, 0x1A, :long, 0)
|
162
|
-
ch.sends_packet(FXP_MKDIR, :long, 4, :string, "/path/to/remote/subdir", :long, 0)
|
163
|
-
ch.sends_packet(FXP_OPEN, :long, 5, :string, "/path/to/remote/subdir/other1", :long, 0x1A, :long, 0)
|
164
|
-
ch.sends_packet(FXP_OPEN, :long, 6, :string, "/path/to/remote/subdir/other2", :long, 0x1A, :long, 0)
|
165
|
-
ch.gets_packet(FXP_HANDLE, :long, 1, :string, "hfile1")
|
166
|
-
ch.sends_packet(FXP_WRITE, :long, 7, :string, "hfile1", :int64, 0, :string, "contents of file1")
|
167
|
-
ch.gets_packet(FXP_HANDLE, :long, 2, :string, "hfile2")
|
168
|
-
ch.sends_packet(FXP_WRITE, :long, 8, :string, "hfile2", :int64, 0, :string, "contents of file2")
|
169
|
-
ch.gets_packet(FXP_HANDLE, :long, 3, :string, "hfile3")
|
170
|
-
ch.sends_packet(FXP_WRITE, :long, 9, :string, "hfile3", :int64, 0, :string, "contents of file3")
|
171
|
-
ch.gets_packet(FXP_STATUS, :long, 4, :long, 0)
|
172
|
-
ch.gets_packet(FXP_HANDLE, :long, 5, :string, "hother1")
|
173
|
-
ch.sends_packet(FXP_CLOSE, :long, 10, :string, "hfile1")
|
174
|
-
ch.sends_packet(FXP_WRITE, :long, 11, :string, "hother1", :int64, 0, :string, "contents of other1")
|
175
|
-
ch.gets_packet(FXP_HANDLE, :long, 6, :string, "hother2")
|
176
|
-
ch.sends_packet(FXP_WRITE, :long, 12, :string, "hother2", :int64, 0, :string, "contents of other2")
|
177
|
-
ch.gets_packet(FXP_STATUS, :long, 7, :long, 0)
|
178
|
-
ch.sends_packet(FXP_CLOSE, :long, 13, :string, "hfile2")
|
179
|
-
ch.gets_packet(FXP_STATUS, :long, 8, :long, 0)
|
180
|
-
ch.sends_packet(FXP_CLOSE, :long, 14, :string, "hfile3")
|
181
|
-
ch.gets_packet(FXP_STATUS, :long, 9, :long, 0)
|
182
|
-
ch.sends_packet(FXP_CLOSE, :long, 15, :string, "hother1")
|
183
|
-
ch.gets_packet(FXP_STATUS, :long, 10, :long, 0)
|
184
|
-
ch.sends_packet(FXP_CLOSE, :long, 16, :string, "hother2")
|
185
|
-
ch.gets_packet(FXP_STATUS, :long, 11, :long, 0)
|
186
|
-
ch.gets_packet(FXP_STATUS, :long, 12, :long, 0)
|
187
|
-
ch.gets_packet(FXP_STATUS, :long, 13, :long, 0)
|
188
|
-
ch.gets_packet(FXP_STATUS, :long, 14, :long, 0)
|
189
|
-
ch.gets_packet(FXP_STATUS, :long, 15, :long, 0)
|
190
|
-
ch.gets_packet(FXP_STATUS, :long, 16, :long, 0)
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def expect_file(path, data)
|
195
|
-
File.stubs(:directory?).with(path).returns(false)
|
196
|
-
File.stubs(:exists?).with(path).returns(true)
|
197
|
-
file = StringIO.new(data)
|
198
|
-
file.stubs(:stat).returns(stub("stat", :size => data.length))
|
199
|
-
File.stubs(:open).with(path, "rb").returns(file)
|
200
|
-
end
|
201
|
-
|
202
|
-
def expect_directory(path, entries)
|
203
|
-
Dir.stubs(:entries).with(path).returns(entries)
|
204
|
-
File.stubs(:directory?).with(path).returns(true)
|
205
|
-
end
|
206
|
-
|
207
|
-
def expect_file_transfer(local, remote, data)
|
208
|
-
expect_sftp_session :server_version => 3 do |channel|
|
209
|
-
channel.sends_packet(FXP_OPEN, :long, 0, :string, remote, :long, 0x1A, :long, 0)
|
210
|
-
channel.gets_packet(FXP_HANDLE, :long, 0, :string, "handle")
|
211
|
-
channel.sends_packet(FXP_WRITE, :long, 1, :string, "handle", :int64, 0, :string, data)
|
212
|
-
channel.sends_packet(FXP_CLOSE, :long, 2, :string, "handle")
|
213
|
-
channel.gets_packet(FXP_STATUS, :long, 1, :long, 0)
|
214
|
-
channel.gets_packet(FXP_STATUS, :long, 2, :long, 0)
|
215
|
-
end
|
216
|
-
|
217
|
-
expect_file(local, data)
|
218
|
-
end
|
219
|
-
end
|