@@ -21,6 +21,20 @@ def test_download_file_should_transfer_remote_to_local
21
21
assert_equal text , file . string
22
22
end
23
23
24
+ def test_download_file_should_transfer_remote_to_local_in_spite_of_fragmentation
25
+ local = "/path/to/local"
26
+ remote = "/path/to/remote"
27
+ text = "this is some text\n "
28
+
29
+ expect_file_transfer ( remote , text , :fragment_len => 1 )
30
+
31
+ file = StringIO . new
32
+ File . stubs ( :open ) . with ( local , "wb" ) . returns ( file )
33
+
34
+ assert_scripted_command { sftp . download ( remote , local ) }
35
+ assert_equal text , file . string
36
+ end
37
+
24
38
def test_download_large_file_should_transfer_remote_to_local
25
39
local = "/path/to/local"
26
40
remote = "/path/to/remote"
@@ -130,12 +144,12 @@ def test_download_directory_to_buffer_should_fail
130
144
131
145
private
132
146
133
- def expect_file_transfer ( remote , text )
147
+ def expect_file_transfer ( remote , text , opts = { } )
134
148
expect_sftp_session :server_version => 3 do |channel |
135
149
channel . sends_packet ( FXP_OPEN , :long , 0 , :string , remote , :long , 0x01 , :long , 0 )
136
150
channel . gets_packet ( FXP_HANDLE , :long , 0 , :string , "handle" )
137
151
channel . sends_packet ( FXP_READ , :long , 1 , :string , "handle" , :int64 , 0 , :long , 32_000 )
138
- channel . gets_packet ( FXP_DATA , :long , 1 , :string , text )
152
+ channel . gets_packet_in_two ( opts [ :fragment_len ] , FXP_DATA , :long , 1 , :string , text )
139
153
channel . sends_packet ( FXP_READ , :long , 2 , :string , "handle" , :int64 , text . bytesize , :long , 32_000 )
140
154
channel . gets_packet ( FXP_STATUS , :long , 2 , :long , 1 )
141
155
channel . sends_packet ( FXP_CLOSE , :long , 3 , :string , "handle" )
@@ -160,7 +174,7 @@ def prepare_large_file_download(local, remote, text, requested_chunk_size = FXP_
160
174
channel . sends_packet ( FXP_CLOSE , :long , data_packet_count + 2 , :string , "handle" )
161
175
channel . gets_packet ( FXP_STATUS , :long , data_packet_count + 2 , :long , 0 )
162
176
end
163
-
177
+
164
178
file = StringIO . new
165
179
File . stubs ( :open ) . with ( local , "wb" ) . returns ( file )
166
180
0 commit comments