net-sftp 1.0.0 → 1.0.1
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.
- data/doc/faq/faq.html +33 -33
- data/doc/faq/faq.yml +1 -1
- data/lib/net/sftp/operations/write.rb +1 -1
- data/lib/net/sftp/protocol/04/impl.rb +16 -64
- data/lib/net/sftp/protocol/04/packet-assistant.rb +0 -6
- data/lib/net/sftp/protocol/05/impl.rb +90 -0
- data/lib/net/sftp/protocol/05/packet-assistant.rb +34 -0
- data/lib/net/sftp/protocol/05/services.rb +4 -4
- data/lib/net/sftp/version.rb +1 -1
- data/test/protocol/04/tc_impl.rb +21 -32
- data/test/protocol/04/tc_packet_assistant.rb +0 -3
- data/test/protocol/05/tc_impl.rb +61 -0
- data/test/protocol/05/tc_packet_assistant.rb +32 -0
- metadata +11 -4
data/doc/faq/faq.html
CHANGED
@@ -60,56 +60,56 @@
|
|
60
60
|
<h1>Net::SFTP FAQ</h1>
|
61
61
|
<div class="faq-list">
|
62
62
|
<ul>
|
63
|
-
<li><a href='#
|
63
|
+
<li><a href='#2224878'>What is Net::SFTP?</a></li>
|
64
64
|
<li>How do I…
|
65
65
|
<ul>
|
66
66
|
<li>...connect to an <span class="caps">SFTP</span> server?
|
67
67
|
<ul>
|
68
|
-
<li><a href='#
|
69
|
-
<li><a href='#
|
68
|
+
<li><a href='#2224778'>I’d like to connect without first getting a Net::SSH connection…</a></li>
|
69
|
+
<li><a href='#2224728'>I already have an open Net::SSH connection…</a></li>
|
70
70
|
</ul>
|
71
71
|
</li>
|
72
72
|
<li>...upload data?
|
73
73
|
<ul>
|
74
|
-
<li><a href='#
|
75
|
-
<li><a href='#
|
74
|
+
<li><a href='#2224628'>I want to upload an entire file on disk…</a></li>
|
75
|
+
<li><a href='#2224588'>I want to upload bytes from a string or other object…</a></li>
|
76
76
|
</ul>
|
77
77
|
</li>
|
78
78
|
<li>...download data?
|
79
79
|
<ul>
|
80
|
-
<li><a href='#
|
81
|
-
<li><a href='#
|
82
|
-
<li><a href='#
|
80
|
+
<li><a href='#2224508'>I want to download directly to a local file…</a></li>
|
81
|
+
<li><a href='#2224458'>I want to download to a string in memory…</a></li>
|
82
|
+
<li><a href='#292410'>I want to be notified of the progress of the download…</a></li>
|
83
83
|
</ul>
|
84
84
|
</li>
|
85
85
|
<li>...manage file permissions?
|
86
86
|
<ul>
|
87
|
-
<li><a href='#
|
88
|
-
<li><a href='#
|
89
|
-
<li><a href='#
|
87
|
+
<li><a href='#292290'>I want to query a file’s permissions…</a></li>
|
88
|
+
<li><a href='#292210'>I want to change a file’s permissions…</a></li>
|
89
|
+
<li><a href='#292130'>I already have an open handle for the remote file…</a></li>
|
90
90
|
</ul>
|
91
91
|
</li>
|
92
92
|
<li>...manage directories?
|
93
93
|
<ul>
|
94
|
-
<li><a href='#
|
95
|
-
<li><a href='#
|
96
|
-
<li><a href='#
|
94
|
+
<li><a href='#291970'>I want to query the contents of a directory…</a></li>
|
95
|
+
<li><a href='#291870'>I want to create a directory…</a></li>
|
96
|
+
<li><a href='#291750'>I want to remove a directory…</a></li>
|
97
97
|
</ul>
|
98
98
|
</li>
|
99
|
-
<li><a href='#
|
100
|
-
<li><a href='#
|
99
|
+
<li><a href='#291670'>...delete a file?</a></li>
|
100
|
+
<li><a href='#291630'>...rename a file?</a></li>
|
101
101
|
</ul>
|
102
102
|
</li>
|
103
103
|
</ul>
|
104
104
|
</div>
|
105
|
-
<a name='
|
105
|
+
<a name='2224878'></a>
|
106
106
|
<div class='faq-title'>What is Net::SFTP?</div>
|
107
107
|
<div class='faq-answer'><p>Net::SFTP is a pure-Ruby implementation of the <span class="caps">SFTP</span> protocol. That’s
|
108
108
|
“SFTP” as in “Secure File Transfer Protocol”, as defined as an adjuct to the
|
109
109
|
<span class="caps">SSH</span> specification. <em>Not</em> “SFTP” as in “Secure <span class="caps">FTP</span>” (a <em>completely</em> different
|
110
110
|
beast). Nor is it an implementation of the “Simple File Transfer Protocol”
|
111
111
|
(which is in no way secure).</p></div>
|
112
|
-
<a name='
|
112
|
+
<a name='2224778'></a>
|
113
113
|
<div class='faq-title'>How do I… ...connect to an <span class="caps">SFTP</span> server? I’d like to connect without first getting a Net::SSH connection…</div>
|
114
114
|
<div class='faq-answer'><p>Something like this:</p>
|
115
115
|
|
@@ -124,7 +124,7 @@ beast). Nor is it an implementation of the “Simple File Transfer Protocol&
|
|
124
124
|
|
125
125
|
<p><code>Net::SFTP.start</code> accepts the same parameters as <code>Net::SSH.start</code>,
|
126
126
|
so I’ll direct you to that documentation for all the particulars.</p></div>
|
127
|
-
<a name='
|
127
|
+
<a name='2224728'></a>
|
128
128
|
<div class='faq-title'>How do I… ...connect to an <span class="caps">SFTP</span> server? I already have an open Net::SSH connection…</div>
|
129
129
|
<div class='faq-answer'><p>You can piggy-back an <span class="caps">SFTP</span> connection on an existing Net::SSH
|
130
130
|
connection, which can be useful if you’ve already got an <span class="caps">SSH</span>
|
@@ -143,7 +143,7 @@ connection that you’re using for port forwarding or whatever.</p>
|
|
143
143
|
...
|
144
144
|
end
|
145
145
|
</pre></code></div>
|
146
|
-
<a name='
|
146
|
+
<a name='2224628'></a>
|
147
147
|
<div class='faq-title'>How do I… ...upload data? I want to upload an entire file on disk…</div>
|
148
148
|
<div class='faq-answer'><p>Assuming you already have an <span class="caps">SFTP</span> connection:</p>
|
149
149
|
|
@@ -151,7 +151,7 @@ connection that you’re using for port forwarding or whatever.</p>
|
|
151
151
|
<code><pre>
|
152
152
|
sftp.put_file "/path/to/local.file", "/path/to/remote.file"
|
153
153
|
</pre></code></div>
|
154
|
-
<a name='
|
154
|
+
<a name='2224588'></a>
|
155
155
|
<div class='faq-title'>How do I… ...upload data? I want to upload bytes from a string or other object…</div>
|
156
156
|
<div class='faq-answer'><p>Assuming you already have an <span class="caps">SFTP</span> connection, and your data is stored
|
157
157
|
in a string named <code>data</code>:</p>
|
@@ -174,7 +174,7 @@ without, but be sure to call <code>close_handle</code> when you’re done:</
|
|
174
174
|
puts result.code # the result of the operation
|
175
175
|
sftp.close_handle(handle)
|
176
176
|
</pre></code></div>
|
177
|
-
<a name='
|
177
|
+
<a name='2224508'></a>
|
178
178
|
<div class='faq-title'>How do I… ...download data? I want to download directly to a local file…</div>
|
179
179
|
<div class='faq-answer'><p>Assuming you already have an <span class="caps">SFTP</span> connection:</p>
|
180
180
|
|
@@ -182,7 +182,7 @@ without, but be sure to call <code>close_handle</code> when you’re done:</
|
|
182
182
|
<code><pre>
|
183
183
|
sftp.get_file "/path/to/remote.file", "/path/to/local.file"
|
184
184
|
</pre></code></div>
|
185
|
-
<a name='
|
185
|
+
<a name='2224458'></a>
|
186
186
|
<div class='faq-title'>How do I… ...download data? I want to download to a string in memory…</div>
|
187
187
|
<div class='faq-answer'><p>Assuming you already have an <span class="caps">SFTP</span> connection:</p>
|
188
188
|
|
@@ -193,7 +193,7 @@ without, but be sure to call <code>close_handle</code> when you’re done:</
|
|
193
193
|
data = sftp.read(handle)
|
194
194
|
end
|
195
195
|
</pre></code></div>
|
196
|
-
<a name='
|
196
|
+
<a name='292410'></a>
|
197
197
|
<div class='faq-title'>How do I… ...download data? I want to be notified of the progress of the download…</div>
|
198
198
|
<div class='faq-answer'><p>You can specify both a “chunk size” and a “progress callback”. The
|
199
199
|
callback will be invoked for every “chunk size” bytes that are
|
@@ -212,7 +212,7 @@ received:</p>
|
|
212
212
|
end
|
213
213
|
end
|
214
214
|
</pre></code></div>
|
215
|
-
<a name='
|
215
|
+
<a name='292290'></a>
|
216
216
|
<div class='faq-title'>How do I… ...manage file permissions? I want to query a file’s permissions…</div>
|
217
217
|
<div class='faq-answer'><p>File permissions are one of the <code>stat</code> attributes of files and
|
218
218
|
directories:</p>
|
@@ -221,7 +221,7 @@ directories:</p>
|
|
221
221
|
<code><pre>
|
222
222
|
p sftp.stat("/path/to/remote.file").permissions
|
223
223
|
</pre></code></div>
|
224
|
-
<a name='
|
224
|
+
<a name='292210'></a>
|
225
225
|
<div class='faq-title'>How do I… ...manage file permissions? I want to change a file’s permissions…</div>
|
226
226
|
<div class='faq-answer'><p>Just use <code>setstat</code> to change the permissions of an existing file:</p>
|
227
227
|
|
@@ -229,8 +229,8 @@ directories:</p>
|
|
229
229
|
<code><pre>
|
230
230
|
sftp.setstat("/path/to/remote.file", :permissions => 0644)
|
231
231
|
</pre></code></div>
|
232
|
-
<a name='
|
233
|
-
<div class='faq-title'>How do I… ...manage file permissions? I already have an open handle for the
|
232
|
+
<a name='292130'></a>
|
233
|
+
<div class='faq-title'>How do I… ...manage file permissions? I already have an open handle for the remote file…</div>
|
234
234
|
<div class='faq-answer'><p>If you have a handle for the remote file, you can use <code>fstat</code> and
|
235
235
|
<code>fsetstat</code> to query and set the permissions:</p>
|
236
236
|
|
@@ -241,7 +241,7 @@ directories:</p>
|
|
241
241
|
sftp.fsetstat(handle, :permissions => permissions | 0444)
|
242
242
|
end
|
243
243
|
</pre></code></div>
|
244
|
-
<a name='
|
244
|
+
<a name='291970'></a>
|
245
245
|
<div class='faq-title'>How do I… ...manage directories? I want to query the contents of a directory…</div>
|
246
246
|
<div class='faq-answer'><p>You query the contents of a directory by calling <code>opendir</code> to obtain
|
247
247
|
a handle to the directory, and then using <code>readdir</code> on the handle to
|
@@ -259,7 +259,7 @@ you’re done:</p>
|
|
259
259
|
end
|
260
260
|
sftp.close_handle(handle)
|
261
261
|
</pre></code></div>
|
262
|
-
<a name='
|
262
|
+
<a name='291870'></a>
|
263
263
|
<div class='faq-title'>How do I… ...manage directories? I want to create a directory…</div>
|
264
264
|
<div class='faq-answer'><p>Use <code>mkdir</code>:</p>
|
265
265
|
|
@@ -267,7 +267,7 @@ you’re done:</p>
|
|
267
267
|
<code><pre>
|
268
268
|
sftp.mkdir("/path/to/remote/dir", :permissions => 0500)
|
269
269
|
</pre></code></div>
|
270
|
-
<a name='
|
270
|
+
<a name='291750'></a>
|
271
271
|
<div class='faq-title'>How do I… ...manage directories? I want to remove a directory…</div>
|
272
272
|
<div class='faq-answer'><p>Use <code>rmdir</code>:</p>
|
273
273
|
|
@@ -275,7 +275,7 @@ you’re done:</p>
|
|
275
275
|
<code><pre>
|
276
276
|
sftp.rmdir("/path/to/remote/dir")
|
277
277
|
</pre></code></div>
|
278
|
-
<a name='
|
278
|
+
<a name='291670'></a>
|
279
279
|
<div class='faq-title'>How do I… ...delete a file?</div>
|
280
280
|
<div class='faq-answer'><p>Use <code>remove</code>:</p>
|
281
281
|
|
@@ -283,7 +283,7 @@ you’re done:</p>
|
|
283
283
|
<code><pre>
|
284
284
|
sftp.remove("/path/to/remote.file")
|
285
285
|
</pre></code></div>
|
286
|
-
<a name='
|
286
|
+
<a name='291630'></a>
|
287
287
|
<div class='faq-title'>How do I… ...rename a file?</div>
|
288
288
|
<div class='faq-answer'><p>Use <code>rename</code>:</p>
|
289
289
|
|
data/doc/faq/faq.yml
CHANGED
@@ -121,7 +121,7 @@
|
|
121
121
|
sftp.setstat("/path/to/remote.file", :permissions => 0644)
|
122
122
|
</pre></code>
|
123
123
|
|
124
|
-
- "I already have an open handle for the
|
124
|
+
- "I already have an open handle for the remote file...": |
|
125
125
|
If you have a handle for the remote file, you can use @fstat@ and
|
126
126
|
@fsetstat@ to query and set the permissions:
|
127
127
|
|
@@ -23,7 +23,7 @@ module Net ; module SFTP ; module Operations
|
|
23
23
|
class Write < Abstract
|
24
24
|
|
25
25
|
# The maximum size of data that will be written at one time.
|
26
|
-
CHUNK_SIZE =
|
26
|
+
CHUNK_SIZE = 32 * 1024
|
27
27
|
|
28
28
|
# Perform the operation. Only CHUNK_SIZE portions of the +data+ parameter
|
29
29
|
# will be written at a time, with subsequent chunks being writteni
|
@@ -21,70 +21,7 @@ module Net ; module SFTP ; module Protocol ; module V_04
|
|
21
21
|
# The implementation of the operations available to version 4 of the SFTP
|
22
22
|
# protocol.
|
23
23
|
class Impl < V_03::Impl
|
24
|
-
|
25
|
-
F_CREATE_NEW = 0x00000000
|
26
|
-
F_CREATE_TRUNCATE = 0x00000001
|
27
|
-
F_OPEN_EXISTING = 0x00000002
|
28
|
-
F_OPEN_OR_CREATE = 0x00000003
|
29
|
-
F_TRUNCATE_EXISTING = 0x00000004
|
30
|
-
|
31
|
-
F_APPEND_DATA = 0x00000008
|
32
|
-
F_APPEND_DATA_ATOMIC = 0x00000010
|
33
|
-
F_TEXT_MODE = 0x00000020
|
34
|
-
F_READ_LOCK = 0x00000040
|
35
|
-
F_WRITE_LOCK = 0x00000080
|
36
|
-
F_DELETE_LOCK = 0x00000100
|
37
|
-
|
38
|
-
module ACE
|
39
|
-
F_READ_DATA = 0x00000001
|
40
|
-
F_LIST_DIRECTORY = 0x00000001
|
41
|
-
F_WRITE_DATA = 0x00000002
|
42
|
-
F_ADD_FILE = 0x00000002
|
43
|
-
F_APPEND_DATA = 0x00000004
|
44
|
-
F_ADD_SUBDIRECTORY = 0x00000004
|
45
|
-
F_READ_NAMED_ATTRS = 0x00000008
|
46
|
-
F_WRITE_NAMED_ATTRS = 0x00000010
|
47
|
-
F_EXECUTE = 0x00000020
|
48
|
-
F_DELETE_CHILD = 0x00000040
|
49
|
-
F_READ_ATTRIBUTES = 0x00000080
|
50
|
-
F_WRITE_ATTRIBUTES = 0x00000100
|
51
|
-
F_DELETE = 0x00010000
|
52
|
-
F_READ_ACL = 0x00020000
|
53
|
-
F_WRITE_ACL = 0x00040000
|
54
|
-
F_WRITE_OWNER = 0x00080000
|
55
|
-
F_SYNCHRONIZE = 0x00100000
|
56
|
-
end
|
57
|
-
|
58
|
-
# The open operation changed in version 4. This method keeps the same
|
59
|
-
# interface as previous versions, but changes how the parameters are
|
60
|
-
# interpreted and converted into a packet.
|
61
|
-
def open( id, path, flags, mode=0660 )
|
62
|
-
sftp_flags, desired_access = case
|
63
|
-
when flags & IO::WRONLY != 0 then
|
64
|
-
[ F_CREATE_TRUNCATE,
|
65
|
-
ACE::F_WRITE_DATA | ACE::F_WRITE_ATTRIBUTES ]
|
66
|
-
when flags & IO::RDWR != 0 then
|
67
|
-
[ F_OPEN_OR_CREATE,
|
68
|
-
ACE::F_READ_DATA | ACE::F_READ_ATTRIBUTES |
|
69
|
-
ACE::F_WRITE_DATA | ACE::F_WRITE_ATTRIBUTES ]
|
70
|
-
when flags & IO::APPEND != 0 then
|
71
|
-
[ F_OPEN_OR_CREATE | F_APPEND_DATA,
|
72
|
-
ACE::F_WRITE_DATA | ACE::F_WRITE_ATTRIBUTES |
|
73
|
-
ACE::F_APPEND_DATA ]
|
74
|
-
else
|
75
|
-
[ F_OPEN_EXISTING,
|
76
|
-
ACE::F_READ_DATA | ACE::F_READ_ATTRIBUTES ]
|
77
|
-
end
|
78
|
-
|
79
|
-
sftp_flags |= F_OPEN_OR_CREATE if flags & IO::CREAT != 0
|
80
|
-
sftp_flags |= F_TRUNCATE_EXISTING if flags & IO::TRUNC != 0
|
81
|
-
|
82
|
-
attributes = @attr_factory.empty
|
83
|
-
attributes.permissions = mode
|
84
|
-
|
85
|
-
open_raw id, path, desired_access, sftp_flags, attributes
|
86
|
-
end
|
87
|
-
|
24
|
+
|
88
25
|
# In version 4, stat accepts a flags parameter. If flags is +nil+, it
|
89
26
|
# will default to returning all attributes. Otherwise, the flags parameter
|
90
27
|
# should be a bitwise combination of the F_xxx constants of
|
@@ -129,6 +66,21 @@ module Net ; module SFTP ; module Protocol ; module V_04
|
|
129
66
|
end
|
130
67
|
private :convert_flags
|
131
68
|
|
69
|
+
# Used internally to handle +name+ packets. The +on_name+ callback is
|
70
|
+
# invoked, if registered, with the driver, id, and array of items. The v4
|
71
|
+
# version of this method sets the 'longname' member of the Name object to
|
72
|
+
# +nil+ (it is not used in this version).
|
73
|
+
def do_name( channel, content )
|
74
|
+
return unless has_on_name?
|
75
|
+
id = content.read_long
|
76
|
+
items = []
|
77
|
+
content.read_long.times do
|
78
|
+
items.push( Name.new( content.read_string, nil,
|
79
|
+
@attr_factory.from_buffer( content ) ) )
|
80
|
+
end
|
81
|
+
call_on_name( driver, id, items )
|
82
|
+
end
|
83
|
+
|
132
84
|
end
|
133
85
|
|
134
86
|
end ; end ; end ; end
|
@@ -21,18 +21,12 @@ module Net ; module SFTP ; module Protocol ; module V_04
|
|
21
21
|
# Version 4 of the SFTP protocol changed the number of parameters to several
|
22
22
|
# different packet types:
|
23
23
|
#
|
24
|
-
# * open( id, path, access, flags, attrs )
|
25
24
|
# * rename( id, old, new, flags )
|
26
25
|
# * stat( id, path, flags )
|
27
26
|
# * lstat( id, path, flags )
|
28
27
|
# * fstat( id, handle, flags )
|
29
28
|
class PacketAssistant < V_03::PacketAssistant
|
30
29
|
|
31
|
-
packet :open, :string, # path
|
32
|
-
:long, # access
|
33
|
-
:long, # flags
|
34
|
-
:attrs # file attributes
|
35
|
-
|
36
30
|
packet :rename, :string, # old name
|
37
31
|
:string, # new name
|
38
32
|
:long # flags
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
+
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'net/sftp/protocol/04/impl'
|
18
|
+
|
19
|
+
module Net ; module SFTP ; module Protocol ; module V_05
|
20
|
+
|
21
|
+
# The implementation of the operations available to version 5 of the SFTP
|
22
|
+
# protocol.
|
23
|
+
class Impl < V_04::Impl
|
24
|
+
|
25
|
+
F_CREATE_NEW = 0x00000000
|
26
|
+
F_CREATE_TRUNCATE = 0x00000001
|
27
|
+
F_OPEN_EXISTING = 0x00000002
|
28
|
+
F_OPEN_OR_CREATE = 0x00000003
|
29
|
+
F_TRUNCATE_EXISTING = 0x00000004
|
30
|
+
|
31
|
+
F_APPEND_DATA = 0x00000008
|
32
|
+
F_APPEND_DATA_ATOMIC = 0x00000010
|
33
|
+
F_TEXT_MODE = 0x00000020
|
34
|
+
F_READ_LOCK = 0x00000040
|
35
|
+
F_WRITE_LOCK = 0x00000080
|
36
|
+
F_DELETE_LOCK = 0x00000100
|
37
|
+
|
38
|
+
module ACE
|
39
|
+
F_READ_DATA = 0x00000001
|
40
|
+
F_LIST_DIRECTORY = 0x00000001
|
41
|
+
F_WRITE_DATA = 0x00000002
|
42
|
+
F_ADD_FILE = 0x00000002
|
43
|
+
F_APPEND_DATA = 0x00000004
|
44
|
+
F_ADD_SUBDIRECTORY = 0x00000004
|
45
|
+
F_READ_NAMED_ATTRS = 0x00000008
|
46
|
+
F_WRITE_NAMED_ATTRS = 0x00000010
|
47
|
+
F_EXECUTE = 0x00000020
|
48
|
+
F_DELETE_CHILD = 0x00000040
|
49
|
+
F_READ_ATTRIBUTES = 0x00000080
|
50
|
+
F_WRITE_ATTRIBUTES = 0x00000100
|
51
|
+
F_DELETE = 0x00010000
|
52
|
+
F_READ_ACL = 0x00020000
|
53
|
+
F_WRITE_ACL = 0x00040000
|
54
|
+
F_WRITE_OWNER = 0x00080000
|
55
|
+
F_SYNCHRONIZE = 0x00100000
|
56
|
+
end
|
57
|
+
|
58
|
+
# The open operation changed in version 4. This method keeps the same
|
59
|
+
# interface as previous versions, but changes how the parameters are
|
60
|
+
# interpreted and converted into a packet.
|
61
|
+
def open( id, path, flags, mode=0660 )
|
62
|
+
sftp_flags, desired_access = case
|
63
|
+
when flags & IO::WRONLY != 0 then
|
64
|
+
[ F_CREATE_TRUNCATE,
|
65
|
+
ACE::F_WRITE_DATA | ACE::F_WRITE_ATTRIBUTES ]
|
66
|
+
when flags & IO::RDWR != 0 then
|
67
|
+
[ F_OPEN_OR_CREATE,
|
68
|
+
ACE::F_READ_DATA | ACE::F_READ_ATTRIBUTES |
|
69
|
+
ACE::F_WRITE_DATA | ACE::F_WRITE_ATTRIBUTES ]
|
70
|
+
when flags & IO::APPEND != 0 then
|
71
|
+
[ F_OPEN_OR_CREATE | F_APPEND_DATA,
|
72
|
+
ACE::F_WRITE_DATA | ACE::F_WRITE_ATTRIBUTES |
|
73
|
+
ACE::F_APPEND_DATA ]
|
74
|
+
else
|
75
|
+
[ F_OPEN_EXISTING,
|
76
|
+
ACE::F_READ_DATA | ACE::F_READ_ATTRIBUTES ]
|
77
|
+
end
|
78
|
+
|
79
|
+
sftp_flags |= F_OPEN_OR_CREATE if flags & IO::CREAT != 0
|
80
|
+
sftp_flags |= F_TRUNCATE_EXISTING if flags & IO::TRUNC != 0
|
81
|
+
|
82
|
+
attributes = @attr_factory.empty
|
83
|
+
attributes.permissions = mode
|
84
|
+
|
85
|
+
open_raw id, path, desired_access, sftp_flags, attributes
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end ; end ; end ; end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
+
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
require 'net/sftp/protocol/04/packet-assistant'
|
18
|
+
|
19
|
+
module Net ; module SFTP ; module Protocol ; module V_05
|
20
|
+
|
21
|
+
# Version 5 of the SFTP protocol changed the number of parameters to several
|
22
|
+
# different packet types:
|
23
|
+
#
|
24
|
+
# * open( id, path, access, flags, attrs )
|
25
|
+
class PacketAssistant < V_04::PacketAssistant
|
26
|
+
|
27
|
+
packet :open, :string, # path
|
28
|
+
:long, # access
|
29
|
+
:long, # flags
|
30
|
+
:attrs # file attributes
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end ; end ; end ; end
|
@@ -20,8 +20,8 @@ module Net ; module SFTP ; module Protocol ; module V_05
|
|
20
20
|
container.namespace_define :v_05 do |ns|
|
21
21
|
|
22
22
|
ns.packet_assistant do |c,|
|
23
|
-
require 'net/sftp/protocol/
|
24
|
-
|
23
|
+
require 'net/sftp/protocol/05/packet-assistant'
|
24
|
+
PacketAssistant.new( c[:transport][:buffers],
|
25
25
|
c[:driver] )
|
26
26
|
end
|
27
27
|
|
@@ -31,8 +31,8 @@ module Net ; module SFTP ; module Protocol ; module V_05
|
|
31
31
|
end
|
32
32
|
|
33
33
|
ns.impl do |c,|
|
34
|
-
require 'net/sftp/protocol/
|
35
|
-
|
34
|
+
require 'net/sftp/protocol/05/impl'
|
35
|
+
Impl.new( c[:transport][:buffers],
|
36
36
|
c[:driver], c[:packet_assistant],
|
37
37
|
c[:attr_factory] )
|
38
38
|
end
|
data/lib/net/sftp/version.rb
CHANGED
data/test/protocol/04/tc_impl.rb
CHANGED
@@ -26,38 +26,6 @@ class TC_04_Impl < TC_03_Impl
|
|
26
26
|
Net::SFTP::Protocol::V_04::Impl
|
27
27
|
end
|
28
28
|
|
29
|
-
unless defined?( IO_FLAGS_V4 )
|
30
|
-
IO_FLAGS_V4 = [ IO::RDONLY, IO::WRONLY, IO::RDWR, IO::APPEND ]
|
31
|
-
OTHER_FLAGS_V4 = [ 0, IO::CREAT, IO::TRUNC, IO::EXCL ]
|
32
|
-
FLAG_MAP_V4 = { IO::RDONLY => 2, IO::WRONLY => 1, IO::RDWR => 3,
|
33
|
-
IO::APPEND => 11, IO::CREAT => 3, IO::TRUNC => 4 }
|
34
|
-
ACCESS_MAP_V4 = { IO::RDONLY => 0x81, IO::WRONLY => 0x102,
|
35
|
-
IO::RDWR => 0x183, IO::APPEND => 0x106 }
|
36
|
-
|
37
|
-
IO_FLAGS_V4.each do |flag|
|
38
|
-
OTHER_FLAGS_V4.each do |oflag|
|
39
|
-
[ nil, 0400 ].each do |mode|
|
40
|
-
define_method( "test_open_#{flag}_#{oflag}_#{mode||"nil"}" ) do
|
41
|
-
return if oflag == IO::EXCL
|
42
|
-
@assistant.mock_handle( :open ) { |*a| [ a[0], a[1..-1] ] }
|
43
|
-
args = [ 14, "a path", flag | oflag ]
|
44
|
-
args << mode if mode
|
45
|
-
assert_equal 14, @impl.open( *args )
|
46
|
-
assert_equal 1, @assistant.mock_count( :open )
|
47
|
-
assert_equal( ( mode || 0660 ), @permissions )
|
48
|
-
sftp_flag = FLAG_MAP_V4[flag] |
|
49
|
-
( oflag == 0 ? 0 : FLAG_MAP_V4[oflag] )
|
50
|
-
access_flag = ACCESS_MAP_V4[flag]
|
51
|
-
assert_equal Net::SFTP::Protocol::Constants::FXP_OPEN,
|
52
|
-
@sent_data.first[0]
|
53
|
-
assert_equal [ "a path", access_flag, sftp_flag ],
|
54
|
-
@sent_data.first[1][0,3]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
29
|
def test_stat_flags
|
62
30
|
@assistant.mock_handle( :stat ) { |*a| [ a[0], a[1..-1] ] }
|
63
31
|
id = @impl.stat( 14, :a, :b )
|
@@ -99,4 +67,25 @@ class TC_04_Impl < TC_03_Impl
|
|
99
67
|
@sent_data
|
100
68
|
end
|
101
69
|
|
70
|
+
# overrides the v1 implementation of the test
|
71
|
+
def test_do_name_with_callback
|
72
|
+
buffer = Net::SSH::Util::ReaderBuffer.new( "\0\0\0\1\0\0\0\2" +
|
73
|
+
"\0\0\0\1a\0\0\0\0" +
|
74
|
+
"\0\0\0\1c\0\0\0\0" )
|
75
|
+
called = false
|
76
|
+
@impl.on_name do |d,i,names|
|
77
|
+
called = true
|
78
|
+
assert_equal 1, i
|
79
|
+
assert_equal 2, names.length
|
80
|
+
assert_equal "a", names.first.filename
|
81
|
+
assert_nil names.first.longname
|
82
|
+
assert_equal 0, names.first.attributes
|
83
|
+
assert_equal "c", names.last.filename
|
84
|
+
assert_nil names.last.longname
|
85
|
+
assert_equal 0, names.last.attributes
|
86
|
+
end
|
87
|
+
@impl.do_name nil, buffer
|
88
|
+
assert called
|
89
|
+
end
|
90
|
+
|
102
91
|
end
|
@@ -26,9 +26,6 @@ class TC_04_PacketAssistant < TC_03_PacketAssistant
|
|
26
26
|
Net::SFTP::Protocol::V_04::PacketAssistant
|
27
27
|
end
|
28
28
|
|
29
|
-
packet :open, [ "a path", 1, 2, "attrs" ],
|
30
|
-
"\0\0\0\6a path\0\0\0\1\0\0\0\2attrs"
|
31
|
-
|
32
29
|
packet :rename, [ "old name", "new name", 1 ],
|
33
30
|
"\0\0\0\10old name\0\0\0\10new name\0\0\0\1"
|
34
31
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
+
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../../../lib"
|
18
|
+
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
+
|
20
|
+
require 'net/sftp/protocol/05/impl'
|
21
|
+
require '04/tc_impl'
|
22
|
+
|
23
|
+
class TC_05_Impl < TC_04_Impl
|
24
|
+
|
25
|
+
def impl_class
|
26
|
+
Net::SFTP::Protocol::V_05::Impl
|
27
|
+
end
|
28
|
+
|
29
|
+
unless defined?( IO_FLAGS_V4 )
|
30
|
+
IO_FLAGS_V4 = [ IO::RDONLY, IO::WRONLY, IO::RDWR, IO::APPEND ]
|
31
|
+
OTHER_FLAGS_V4 = [ 0, IO::CREAT, IO::TRUNC, IO::EXCL ]
|
32
|
+
FLAG_MAP_V4 = { IO::RDONLY => 2, IO::WRONLY => 1, IO::RDWR => 3,
|
33
|
+
IO::APPEND => 11, IO::CREAT => 3, IO::TRUNC => 4 }
|
34
|
+
ACCESS_MAP_V4 = { IO::RDONLY => 0x81, IO::WRONLY => 0x102,
|
35
|
+
IO::RDWR => 0x183, IO::APPEND => 0x106 }
|
36
|
+
|
37
|
+
IO_FLAGS_V4.each do |flag|
|
38
|
+
OTHER_FLAGS_V4.each do |oflag|
|
39
|
+
[ nil, 0400 ].each do |mode|
|
40
|
+
define_method( "test_open_#{flag}_#{oflag}_#{mode||"nil"}" ) do
|
41
|
+
return if oflag == IO::EXCL
|
42
|
+
@assistant.mock_handle( :open ) { |*a| [ a[0], a[1..-1] ] }
|
43
|
+
args = [ 14, "a path", flag | oflag ]
|
44
|
+
args << mode if mode
|
45
|
+
assert_equal 14, @impl.open( *args )
|
46
|
+
assert_equal 1, @assistant.mock_count( :open )
|
47
|
+
assert_equal( ( mode || 0660 ), @permissions )
|
48
|
+
sftp_flag = FLAG_MAP_V4[flag] |
|
49
|
+
( oflag == 0 ? 0 : FLAG_MAP_V4[oflag] )
|
50
|
+
access_flag = ACCESS_MAP_V4[flag]
|
51
|
+
assert_equal Net::SFTP::Protocol::Constants::FXP_OPEN,
|
52
|
+
@sent_data.first[0]
|
53
|
+
assert_equal [ "a path", access_flag, sftp_flag ],
|
54
|
+
@sent_data.first[1][0,3]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
# =============================================================================
|
3
|
+
# Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
|
4
|
+
# All rights reserved.
|
5
|
+
#
|
6
|
+
# This source file is distributed as part of the Net::SFTP Secure FTP Client
|
7
|
+
# library for Ruby. This file (and the library as a whole) may be used only as
|
8
|
+
# allowed by either the BSD license, or the Ruby license (or, by association
|
9
|
+
# with the Ruby license, the GPL). See the "doc" subdirectory of the Net::SFTP
|
10
|
+
# distribution for the texts of these licenses.
|
11
|
+
# -----------------------------------------------------------------------------
|
12
|
+
# net-sftp website: http://net-ssh.rubyforge.org/sftp
|
13
|
+
# project website : http://rubyforge.org/projects/net-ssh
|
14
|
+
# =============================================================================
|
15
|
+
#++
|
16
|
+
|
17
|
+
$:.unshift "../../../lib"
|
18
|
+
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
|
19
|
+
|
20
|
+
require '04/tc_packet_assistant'
|
21
|
+
require 'net/sftp/protocol/05/packet-assistant'
|
22
|
+
|
23
|
+
class TC_05_PacketAssistant < TC_04_PacketAssistant
|
24
|
+
|
25
|
+
def packet_assistant_class
|
26
|
+
Net::SFTP::Protocol::V_05::PacketAssistant
|
27
|
+
end
|
28
|
+
|
29
|
+
packet :open, [ "a path", 1, 2, "attrs" ],
|
30
|
+
"\0\0\0\6a path\0\0\0\1\0\0\0\2attrs"
|
31
|
+
|
32
|
+
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.11
|
3
3
|
specification_version: 1
|
4
4
|
name: net-sftp
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2005-06-
|
6
|
+
version: 1.0.1
|
7
|
+
date: 2005-12-06 00:00:00 -07:00
|
8
8
|
summary: Net::SFTP is a pure-Ruby implementation of the SFTP client protocol.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -24,6 +24,8 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
|
|
24
24
|
version: 0.0.0
|
25
25
|
version:
|
26
26
|
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
27
29
|
authors:
|
28
30
|
- Jamis Buck
|
29
31
|
files:
|
@@ -85,6 +87,8 @@ files:
|
|
85
87
|
- lib/net/sftp/protocol/04/impl.rb
|
86
88
|
- lib/net/sftp/protocol/04/packet-assistant.rb
|
87
89
|
- lib/net/sftp/protocol/04/services.rb
|
90
|
+
- lib/net/sftp/protocol/05/impl.rb
|
91
|
+
- lib/net/sftp/protocol/05/packet-assistant.rb
|
88
92
|
- lib/net/sftp/protocol/05/services.rb
|
89
93
|
- lib/uri/open-sftp.rb
|
90
94
|
- lib/uri/sftp.rb
|
@@ -116,6 +120,7 @@ files:
|
|
116
120
|
- test/protocol/02
|
117
121
|
- test/protocol/03
|
118
122
|
- test/protocol/04
|
123
|
+
- test/protocol/05
|
119
124
|
- test/protocol/tc_driver.rb
|
120
125
|
- test/protocol/01/tc_attributes.rb
|
121
126
|
- test/protocol/01/tc_impl.rb
|
@@ -127,6 +132,8 @@ files:
|
|
127
132
|
- test/protocol/04/tc_attributes.rb
|
128
133
|
- test/protocol/04/tc_impl.rb
|
129
134
|
- test/protocol/04/tc_packet_assistant.rb
|
135
|
+
- test/protocol/05/tc_impl.rb
|
136
|
+
- test/protocol/05/tc_packet_assistant.rb
|
130
137
|
test_files:
|
131
138
|
- test/ALL-TESTS.rb
|
132
139
|
rdoc_options: []
|
@@ -143,5 +150,5 @@ dependencies:
|
|
143
150
|
-
|
144
151
|
- ">="
|
145
152
|
- !ruby/object:Gem::Version
|
146
|
-
version: 0.
|
153
|
+
version: 1.0.0
|
147
154
|
version:
|