net-sftp 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +23 -0
- data/Manifest +55 -0
- data/README.rdoc +96 -0
- data/Rakefile +30 -0
- data/lib/net/sftp.rb +53 -38
- data/lib/net/sftp/constants.rb +187 -0
- data/lib/net/sftp/errors.rb +34 -20
- data/lib/net/sftp/operations/dir.rb +93 -0
- data/lib/net/sftp/operations/download.rb +364 -0
- data/lib/net/sftp/operations/file.rb +176 -0
- data/lib/net/sftp/operations/file_factory.rb +60 -0
- data/lib/net/sftp/operations/upload.rb +387 -0
- data/lib/net/sftp/packet.rb +21 -0
- data/lib/net/sftp/protocol.rb +32 -0
- data/lib/net/sftp/protocol/01/attributes.rb +265 -96
- data/lib/net/sftp/protocol/01/base.rb +268 -0
- data/lib/net/sftp/protocol/01/name.rb +43 -0
- data/lib/net/sftp/protocol/02/base.rb +31 -0
- data/lib/net/sftp/protocol/03/base.rb +35 -0
- data/lib/net/sftp/protocol/04/attributes.rb +120 -195
- data/lib/net/sftp/protocol/04/base.rb +94 -0
- data/lib/net/sftp/protocol/04/name.rb +67 -0
- data/lib/net/sftp/protocol/05/base.rb +66 -0
- data/lib/net/sftp/protocol/06/attributes.rb +107 -0
- data/lib/net/sftp/protocol/06/base.rb +63 -0
- data/lib/net/sftp/protocol/base.rb +50 -0
- data/lib/net/sftp/request.rb +91 -0
- data/lib/net/sftp/response.rb +76 -0
- data/lib/net/sftp/session.rb +914 -238
- data/lib/net/sftp/version.rb +14 -21
- data/net-sftp.gemspec +60 -0
- data/setup.rb +1331 -0
- data/test/common.rb +173 -0
- data/test/protocol/01/test_attributes.rb +97 -0
- data/test/protocol/01/test_base.rb +210 -0
- data/test/protocol/01/test_name.rb +27 -0
- data/test/protocol/02/test_base.rb +26 -0
- data/test/protocol/03/test_base.rb +27 -0
- data/test/protocol/04/test_attributes.rb +148 -0
- data/test/protocol/04/test_base.rb +74 -0
- data/test/protocol/04/test_name.rb +49 -0
- data/test/protocol/05/test_base.rb +62 -0
- data/test/protocol/06/test_attributes.rb +124 -0
- data/test/protocol/06/test_base.rb +51 -0
- data/test/protocol/test_base.rb +42 -0
- data/test/test_all.rb +3 -0
- data/test/test_dir.rb +47 -0
- data/test/test_download.rb +252 -0
- data/test/test_file.rb +159 -0
- data/test/test_file_factory.rb +48 -0
- data/test/test_packet.rb +9 -0
- data/test/test_protocol.rb +17 -0
- data/test/test_request.rb +71 -0
- data/test/test_response.rb +53 -0
- data/test/test_session.rb +741 -0
- data/test/test_upload.rb +219 -0
- metadata +59 -111
- data/doc/LICENSE-BSD +0 -27
- data/doc/LICENSE-GPL +0 -280
- data/doc/LICENSE-RUBY +0 -56
- data/doc/faq/faq.html +0 -298
- data/doc/faq/faq.rb +0 -154
- data/doc/faq/faq.yml +0 -183
- data/examples/asynchronous.rb +0 -57
- data/examples/get-put.rb +0 -45
- data/examples/sftp-open-uri.rb +0 -30
- data/examples/ssh-service.rb +0 -30
- data/examples/synchronous.rb +0 -131
- data/lib/net/sftp/operations/abstract.rb +0 -108
- data/lib/net/sftp/operations/close.rb +0 -31
- data/lib/net/sftp/operations/errors.rb +0 -76
- data/lib/net/sftp/operations/fsetstat.rb +0 -36
- data/lib/net/sftp/operations/fstat.rb +0 -32
- data/lib/net/sftp/operations/lstat.rb +0 -31
- data/lib/net/sftp/operations/mkdir.rb +0 -33
- data/lib/net/sftp/operations/open.rb +0 -32
- data/lib/net/sftp/operations/opendir.rb +0 -32
- data/lib/net/sftp/operations/read.rb +0 -88
- data/lib/net/sftp/operations/readdir.rb +0 -55
- data/lib/net/sftp/operations/realpath.rb +0 -37
- data/lib/net/sftp/operations/remove.rb +0 -31
- data/lib/net/sftp/operations/rename.rb +0 -32
- data/lib/net/sftp/operations/rmdir.rb +0 -31
- data/lib/net/sftp/operations/services.rb +0 -42
- data/lib/net/sftp/operations/setstat.rb +0 -33
- data/lib/net/sftp/operations/stat.rb +0 -31
- data/lib/net/sftp/operations/write.rb +0 -63
- data/lib/net/sftp/protocol/01/impl.rb +0 -251
- data/lib/net/sftp/protocol/01/packet-assistant.rb +0 -82
- data/lib/net/sftp/protocol/01/services.rb +0 -47
- data/lib/net/sftp/protocol/02/impl.rb +0 -39
- data/lib/net/sftp/protocol/02/packet-assistant.rb +0 -32
- data/lib/net/sftp/protocol/02/services.rb +0 -44
- data/lib/net/sftp/protocol/03/impl.rb +0 -42
- data/lib/net/sftp/protocol/03/packet-assistant.rb +0 -35
- data/lib/net/sftp/protocol/03/services.rb +0 -44
- data/lib/net/sftp/protocol/04/impl.rb +0 -86
- data/lib/net/sftp/protocol/04/packet-assistant.rb +0 -45
- data/lib/net/sftp/protocol/04/services.rb +0 -44
- data/lib/net/sftp/protocol/05/impl.rb +0 -90
- data/lib/net/sftp/protocol/05/packet-assistant.rb +0 -34
- data/lib/net/sftp/protocol/05/services.rb +0 -44
- data/lib/net/sftp/protocol/constants.rb +0 -60
- data/lib/net/sftp/protocol/driver.rb +0 -235
- data/lib/net/sftp/protocol/packet-assistant.rb +0 -84
- data/lib/net/sftp/protocol/services.rb +0 -55
- data/lib/uri/open-sftp.rb +0 -54
- data/lib/uri/sftp.rb +0 -42
- data/test/ALL-TESTS.rb +0 -23
- data/test/operations/tc_abstract.rb +0 -124
- data/test/operations/tc_close.rb +0 -40
- data/test/operations/tc_fsetstat.rb +0 -48
- data/test/operations/tc_fstat.rb +0 -40
- data/test/operations/tc_lstat.rb +0 -40
- data/test/operations/tc_mkdir.rb +0 -48
- data/test/operations/tc_open.rb +0 -42
- data/test/operations/tc_opendir.rb +0 -40
- data/test/operations/tc_read.rb +0 -103
- data/test/operations/tc_readdir.rb +0 -88
- data/test/operations/tc_realpath.rb +0 -54
- data/test/operations/tc_remove.rb +0 -40
- data/test/operations/tc_rmdir.rb +0 -40
- data/test/operations/tc_setstat.rb +0 -48
- data/test/operations/tc_stat.rb +0 -40
- data/test/operations/tc_write.rb +0 -91
- data/test/protocol/01/tc_attributes.rb +0 -138
- data/test/protocol/01/tc_impl.rb +0 -294
- data/test/protocol/01/tc_packet_assistant.rb +0 -81
- data/test/protocol/02/tc_impl.rb +0 -41
- data/test/protocol/02/tc_packet_assistant.rb +0 -31
- data/test/protocol/03/tc_impl.rb +0 -48
- data/test/protocol/03/tc_packet_assistant.rb +0 -34
- data/test/protocol/04/tc_attributes.rb +0 -174
- data/test/protocol/04/tc_impl.rb +0 -91
- data/test/protocol/04/tc_packet_assistant.rb +0 -38
- data/test/protocol/05/tc_impl.rb +0 -61
- data/test/protocol/05/tc_packet_assistant.rb +0 -32
- data/test/protocol/tc_driver.rb +0 -219
@@ -1,33 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
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/operations/abstract'
|
18
|
-
|
19
|
-
module Net ; module SFTP ; module Operations
|
20
|
-
|
21
|
-
# Implements the +setstat+ operation.
|
22
|
-
class Setstat < Abstract
|
23
|
-
|
24
|
-
# Perform the operation. The +hash+ parameter is a hash of attributes that
|
25
|
-
# should be set on the file or directory indicated by the +path+.
|
26
|
-
def perform( path, hash )
|
27
|
-
attrs = @driver.attr_factory.from_hash( hash )
|
28
|
-
@driver.setstat( nil, path, attrs )
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
end ; end ; end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
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/operations/abstract'
|
18
|
-
|
19
|
-
module Net ; module SFTP ; module Operations
|
20
|
-
|
21
|
-
# Implements the +stat+ operation.
|
22
|
-
class Stat < Abstract
|
23
|
-
|
24
|
-
# Perform the operation.
|
25
|
-
def perform( path )
|
26
|
-
@driver.stat( nil, path )
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end ; end ; end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
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/operations/abstract'
|
18
|
-
|
19
|
-
module Net ; module SFTP ; module Operations
|
20
|
-
|
21
|
-
# Implements the +write+ operation. Handles, automatically, the looping
|
22
|
-
# necessary to write a large data set.
|
23
|
-
class Write < Abstract
|
24
|
-
|
25
|
-
# The maximum size of data that will be written at one time.
|
26
|
-
CHUNK_SIZE = 32 * 1024
|
27
|
-
|
28
|
-
# Perform the operation. Only CHUNK_SIZE portions of the +data+ parameter
|
29
|
-
# will be written at a time, with subsequent chunks being writteni
|
30
|
-
# automatically when prior chunks complete.
|
31
|
-
def perform( handle, data, offset=0 )
|
32
|
-
@handle = handle
|
33
|
-
@offset = offset
|
34
|
-
@data = data
|
35
|
-
@pos = 0
|
36
|
-
|
37
|
-
@driver.write( nil, handle, offset, data[0,CHUNK_SIZE] )
|
38
|
-
end
|
39
|
-
|
40
|
-
# Invoked when the server sends a status packet. If the status is FX_OK,
|
41
|
-
# then the callback is invoked (if all data has been written), or the
|
42
|
-
# next chunk is written to the server (if more data remains). Other
|
43
|
-
# status codes are handled by the superclass.
|
44
|
-
def do_status( code, message, language )
|
45
|
-
if code == FX_OK
|
46
|
-
@log.debug "[#{@id}] chunk written" if @log.debug?
|
47
|
-
@pos += CHUNK_SIZE
|
48
|
-
|
49
|
-
if @pos > @data.length
|
50
|
-
@callback[ OK ]
|
51
|
-
return
|
52
|
-
end
|
53
|
-
|
54
|
-
@driver.write @id, @handle, @offset + @pos, @data[@pos,CHUNK_SIZE]
|
55
|
-
@session.register @id, self
|
56
|
-
else
|
57
|
-
super
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end ; end ; end
|
@@ -1,251 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
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/errors'
|
18
|
-
require 'net/sftp/protocol/constants'
|
19
|
-
|
20
|
-
module Net ; module SFTP ; module Protocol ; module V_01
|
21
|
-
|
22
|
-
# The implementing class for version 1 of the SFTP protocol. It
|
23
|
-
# implements the various operations and callbacks available to this
|
24
|
-
# level of the protocol. Other protocol versions will typically
|
25
|
-
# extend this class, adding (or modifying) methods as needed to bring
|
26
|
-
# the implementation into sync with the needed version.
|
27
|
-
class Impl
|
28
|
-
include Constants
|
29
|
-
|
30
|
-
Name = Struct.new( :filename, :longname, :attributes )
|
31
|
-
|
32
|
-
# The protocol driver that drives this dispatcher.
|
33
|
-
attr_reader :driver
|
34
|
-
|
35
|
-
# The attribute-factory used by this dispatcher.
|
36
|
-
attr_reader :attr_factory
|
37
|
-
|
38
|
-
# The protocol extensions specified when the protocol version was
|
39
|
-
# negotiated.
|
40
|
-
attr_accessor :extensions
|
41
|
-
|
42
|
-
# Create a new instance using the given protocol driver, packet
|
43
|
-
# assistant, and attributes factory.
|
44
|
-
def initialize( buffers, driver, assistant, attr_factory )
|
45
|
-
@buffers = buffers
|
46
|
-
@driver = driver
|
47
|
-
@assistant = assistant
|
48
|
-
@attr_factory = attr_factory
|
49
|
-
@on_status = nil
|
50
|
-
@on_handle = nil
|
51
|
-
@on_data = nil
|
52
|
-
@on_name = nil
|
53
|
-
@on_attrs = nil
|
54
|
-
end
|
55
|
-
|
56
|
-
# A helper method for defining new operations supported by this
|
57
|
-
# implementation. This will create one method for each named operation.
|
58
|
-
# By default, the method simply formats the packet (using the packet
|
59
|
-
# assistant), and then sends the data via the driver. It will then
|
60
|
-
# return the request id used for this operation.
|
61
|
-
def self.operation( *names )
|
62
|
-
names.each do |name|
|
63
|
-
const = "FXP_#{name.to_s.upcase}"
|
64
|
-
class_eval <<-EOF, __FILE__, __LINE__+1
|
65
|
-
def #{name}( id, *args )
|
66
|
-
id, packet = @assistant.#{name}( id, *args )
|
67
|
-
@driver.send_data #{const}, packet
|
68
|
-
id
|
69
|
-
end
|
70
|
-
EOF
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# A helper method for registering new callbacks. Each callback will
|
75
|
-
# cause three new methods to be created, <tt>on_<em>name</em></tt>,
|
76
|
-
# <tt>has_on_<em>name</em>?</tt>, and <tt>call_on_<em>name</em></tt>.
|
77
|
-
# The <tt>on_<em>name</em></tt> method may be used to register a block
|
78
|
-
# for the corresponding callback.
|
79
|
-
def self.callback( *names )
|
80
|
-
names.each do |name|
|
81
|
-
class_eval <<-EOF, __FILE__, __LINE__+1
|
82
|
-
def on_#{name}( &block )
|
83
|
-
@on_#{name} = block
|
84
|
-
end
|
85
|
-
|
86
|
-
def has_on_#{name}?
|
87
|
-
not @on_#{name}.nil?
|
88
|
-
end
|
89
|
-
|
90
|
-
def call_on_#{name}( *args )
|
91
|
-
return unless @on_#{name}
|
92
|
-
@on_#{name}.call( *args )
|
93
|
-
end
|
94
|
-
|
95
|
-
public :on_#{name}
|
96
|
-
protected :has_on_#{name}?, :call_on_#{name}
|
97
|
-
EOF
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
operation :open,
|
102
|
-
:close,
|
103
|
-
:read,
|
104
|
-
:write,
|
105
|
-
:opendir,
|
106
|
-
:readdir,
|
107
|
-
:remove,
|
108
|
-
:stat,
|
109
|
-
:lstat,
|
110
|
-
:fstat,
|
111
|
-
:setstat,
|
112
|
-
:fsetstat,
|
113
|
-
:mkdir,
|
114
|
-
:rmdir,
|
115
|
-
:realpath
|
116
|
-
|
117
|
-
callback :status,
|
118
|
-
:handle,
|
119
|
-
:data,
|
120
|
-
:name,
|
121
|
-
:attrs
|
122
|
-
|
123
|
-
alias :open_raw :open
|
124
|
-
alias :stat_raw :stat
|
125
|
-
alias :lstat_raw :lstat
|
126
|
-
alias :fstat_raw :fstat
|
127
|
-
|
128
|
-
alias :close_handle :close
|
129
|
-
|
130
|
-
F_READ = 0x00000001
|
131
|
-
F_WRITE = 0x00000002
|
132
|
-
F_APPEND = 0x00000004
|
133
|
-
F_CREAT = 0x00000008
|
134
|
-
F_TRUNC = 0x00000010
|
135
|
-
F_EXCL = 0x00000020
|
136
|
-
|
137
|
-
# The open operation is special, since it protects the caller from the
|
138
|
-
# specific flags and options required by SFTP. Instead, the caller simply
|
139
|
-
# specifies a combination of IO flags, and an appropriate posix mode, and
|
140
|
-
# they are translated into the correct SFTP flags.
|
141
|
-
def open( id, path, flags, mode=0660 )
|
142
|
-
sftp_flags = case
|
143
|
-
when ( flags & IO::WRONLY ) != 0 then F_WRITE
|
144
|
-
when ( flags & IO::RDWR ) != 0 then F_READ | F_WRITE
|
145
|
-
when ( flags & IO::APPEND ) != 0 then F_APPEND
|
146
|
-
else F_READ
|
147
|
-
end
|
148
|
-
|
149
|
-
sftp_flags |= F_CREAT if ( flags & IO::CREAT ) != 0
|
150
|
-
sftp_flags |= F_TRUNC if ( flags & IO::TRUNC ) != 0
|
151
|
-
sftp_flags |= F_EXCL if ( flags & IO::EXCL ) != 0
|
152
|
-
|
153
|
-
attributes = @attr_factory.empty
|
154
|
-
attributes.permissions = mode
|
155
|
-
|
156
|
-
open_raw id, path, sftp_flags, attributes
|
157
|
-
end
|
158
|
-
|
159
|
-
# The stat operation is special, since later versions of the protocol add
|
160
|
-
# support for 'flags'. These flags are ignored in this version, but the
|
161
|
-
# parameter exists to allow a program written for one version of the
|
162
|
-
# protocol to work with later versions.
|
163
|
-
def stat( id, filename, flags=nil )
|
164
|
-
stat_raw id, filename
|
165
|
-
end
|
166
|
-
|
167
|
-
# The lstat operation is special, since later versions of the protocol add
|
168
|
-
# support for 'flags'. These flags are ignored in this version, but the
|
169
|
-
# parameter exists to allow a program written for one version of the
|
170
|
-
# protocol to work with later versions.
|
171
|
-
def lstat( id, filename, flags=nil )
|
172
|
-
lstat_raw id, filename
|
173
|
-
end
|
174
|
-
|
175
|
-
# The fstat operation is special, since later versions of the protocol add
|
176
|
-
# support for 'flags'. These flags are ignored in this version, but the
|
177
|
-
# parameter exists to allow a program written for one version of the
|
178
|
-
# protocol to work with later versions.
|
179
|
-
def fstat( id, handle, flags=nil )
|
180
|
-
fstat_raw id, handle
|
181
|
-
end
|
182
|
-
|
183
|
-
# Dispatches the given packet type to the appropriate handler method.
|
184
|
-
# If a new protocol version adds a new packet type, it should override
|
185
|
-
# this method, performing its own checking first, followed by calling
|
186
|
-
# +super+.
|
187
|
-
def dispatch( channel, type, content )
|
188
|
-
case type
|
189
|
-
when FXP_STATUS then do_status( channel, content )
|
190
|
-
when FXP_HANDLE then do_handle( channel, content )
|
191
|
-
when FXP_DATA then do_data( channel, content )
|
192
|
-
when FXP_NAME then do_name( channel, content )
|
193
|
-
when FXP_ATTRS then do_attrs( channel, content )
|
194
|
-
else
|
195
|
-
raise Net::SFTP::Exception,
|
196
|
-
"unsupported SFTP packet type #{type} (#{content.to_s.inspect})"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Used internally to handle +status+ packets. The +on_status+ callback is
|
201
|
-
# invoked, if registered, with the driver, id, and code.
|
202
|
-
def do_status( channel, content )
|
203
|
-
return unless has_on_status?
|
204
|
-
id = content.read_long
|
205
|
-
code = content.read_long
|
206
|
-
call_on_status( driver, id, code, nil, nil )
|
207
|
-
end
|
208
|
-
|
209
|
-
# Used internally to handle +handle+ packets. The +on_handle+ callback is
|
210
|
-
# invoked, if registered, with the driver, id, and handle.
|
211
|
-
def do_handle( channel, content )
|
212
|
-
return unless has_on_handle?
|
213
|
-
id = content.read_long
|
214
|
-
handle = content.read_string
|
215
|
-
call_on_handle( driver, id, handle )
|
216
|
-
end
|
217
|
-
|
218
|
-
# Used internally to handle +data+ packets. The +on_data+ callback is
|
219
|
-
# invoked, if registered, with the driver, id, and data (as a buffer).
|
220
|
-
def do_data( channel, content )
|
221
|
-
return unless has_on_data?
|
222
|
-
id = content.read_long
|
223
|
-
data = content.read_string
|
224
|
-
call_on_data( driver, id, data )
|
225
|
-
end
|
226
|
-
|
227
|
-
# Used internally to handle +name+ packets. The +on_name+ callback is
|
228
|
-
# invoked, if registered, with the driver, id, and array of items.
|
229
|
-
def do_name( channel, content )
|
230
|
-
return unless has_on_name?
|
231
|
-
id = content.read_long
|
232
|
-
items = []
|
233
|
-
content.read_long.times do
|
234
|
-
items.push( Name.new( content.read_string, content.read_string,
|
235
|
-
@attr_factory.from_buffer( content ) ) )
|
236
|
-
end
|
237
|
-
call_on_name( driver, id, items )
|
238
|
-
end
|
239
|
-
|
240
|
-
# Used internally to handle +attrs+ packets. The +on_attrs+ callback is
|
241
|
-
# invoked, if registered, with the driver, id, and attribute object.
|
242
|
-
def do_attrs( channel, content )
|
243
|
-
return unless has_on_attrs?
|
244
|
-
id = content.read_long
|
245
|
-
attrs = @attr_factory.from_buffer( content )
|
246
|
-
call_on_attrs( driver, id, attrs )
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
|
-
end ; end ; end ; end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
#--
|
2
|
-
# =============================================================================
|
3
|
-
# Copyright (c) 2004, Jamis Buck (jamis@37signals.com)
|
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/packet-assistant'
|
18
|
-
|
19
|
-
module Net ; module SFTP ; module Protocol ; module V_01
|
20
|
-
|
21
|
-
# Defines the packets available to version 1 of the SFTP protocol, as well
|
22
|
-
# as their formats. These packets are:
|
23
|
-
#
|
24
|
-
# * open( id, path, flags, attrs )
|
25
|
-
# * close( id, handle )
|
26
|
-
# * read( id, handle, offset, length )
|
27
|
-
# * write( id, handle, offset, data )
|
28
|
-
# * opendir( id, path )
|
29
|
-
# * readdir( id, handle )
|
30
|
-
# * remove( id, filename )
|
31
|
-
# * stat( id, path )
|
32
|
-
# * lstat( id, path )
|
33
|
-
# * fstat( id, handle )
|
34
|
-
# * setstat( id, path, attrs )
|
35
|
-
# * fsetstat( id, handle, attrs )
|
36
|
-
# * mkdir( id, path, attrs )
|
37
|
-
# * rmdir( id, path )
|
38
|
-
# * realpath( id, path )
|
39
|
-
class PacketAssistant < Protocol::PacketAssistant
|
40
|
-
|
41
|
-
packet :open, :string, # path
|
42
|
-
:long, # flags
|
43
|
-
:attrs # file attributes
|
44
|
-
|
45
|
-
packet :close, :string # handle
|
46
|
-
|
47
|
-
packet :read, :string, # handle
|
48
|
-
:int64, # offset
|
49
|
-
:long # length
|
50
|
-
|
51
|
-
packet :write, :string, # handle
|
52
|
-
:int64, # offset
|
53
|
-
:string # data
|
54
|
-
|
55
|
-
packet :opendir, :string # path
|
56
|
-
|
57
|
-
packet :readdir, :string # handle
|
58
|
-
|
59
|
-
packet :remove, :string # filename
|
60
|
-
|
61
|
-
packet :stat, :string # path
|
62
|
-
|
63
|
-
packet :lstat, :string # path
|
64
|
-
|
65
|
-
packet :fstat, :string # handle
|
66
|
-
|
67
|
-
packet :setstat, :string, # path
|
68
|
-
:attrs # attributes to set
|
69
|
-
|
70
|
-
packet :fsetstat, :string, # handle
|
71
|
-
:attrs # attributes to set
|
72
|
-
|
73
|
-
packet :mkdir, :string, # path
|
74
|
-
:attrs # directory attributes
|
75
|
-
|
76
|
-
packet :rmdir, :string # path
|
77
|
-
|
78
|
-
packet :realpath, :string # path
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
end ; end ; end ; end
|