hrr_rb_sftp 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -0
- data/lib/hrr_rb_sftp.rb +79 -1
- data/lib/hrr_rb_sftp/loggable.rb +34 -0
- data/lib/hrr_rb_sftp/protocol.rb +39 -33
- data/lib/hrr_rb_sftp/protocol/common.rb +6 -3
- data/lib/hrr_rb_sftp/protocol/common/data_types.rb +19 -0
- data/lib/hrr_rb_sftp/protocol/common/data_types/byte.rb +40 -0
- data/lib/hrr_rb_sftp/protocol/common/data_types/extension_pair.rb +41 -0
- data/lib/hrr_rb_sftp/protocol/common/data_types/extension_pairs.rb +42 -0
- data/lib/hrr_rb_sftp/protocol/common/data_types/string.rb +42 -0
- data/lib/hrr_rb_sftp/protocol/common/data_types/uint32.rb +40 -0
- data/lib/hrr_rb_sftp/protocol/common/data_types/uint64.rb +40 -0
- data/lib/hrr_rb_sftp/protocol/common/packets.rb +16 -0
- data/lib/hrr_rb_sftp/protocol/common/packets/001_ssh_fxp_init.rb +27 -0
- data/lib/hrr_rb_sftp/protocol/common/packets/002_ssh_fxp_version.rb +28 -0
- data/lib/hrr_rb_sftp/protocol/common/packets/packet.rb +96 -0
- data/lib/hrr_rb_sftp/protocol/version1.rb +11 -3
- data/lib/hrr_rb_sftp/protocol/version1/data_types.rb +15 -0
- data/lib/hrr_rb_sftp/protocol/version1/data_types/attrs.rb +91 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets.rb +72 -0
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/003_ssh_fxp_open.rb +94 -43
- data/lib/hrr_rb_sftp/protocol/version1/packets/004_ssh_fxp_close.rb +61 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/005_ssh_fxp_read.rb +72 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/006_ssh_fxp_write.rb +64 -0
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/007_ssh_fxp_lstat.rb +27 -9
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/008_ssh_fxp_fstat.rb +26 -9
- data/lib/hrr_rb_sftp/protocol/version1/packets/009_ssh_fxp_setstat.rb +92 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/010_ssh_fxp_fsetstat.rb +85 -0
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/011_ssh_fxp_opendir.rb +32 -11
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/012_ssh_fxp_readdir.rb +73 -49
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/013_ssh_fxp_remove.rb +27 -9
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/014_ssh_fxp_mkdir.rb +28 -10
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/015_ssh_fxp_rmdir.rb +32 -12
- data/lib/hrr_rb_sftp/protocol/version1/packets/016_ssh_fxp_realpath.rb +47 -0
- data/lib/hrr_rb_sftp/protocol/version1/{packet → packets}/017_ssh_fxp_stat.rb +27 -9
- data/lib/hrr_rb_sftp/protocol/version1/packets/101_ssh_fxp_status.rb +73 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/102_ssh_fxp_handle.rb +28 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/103_ssh_fxp_data.rb +28 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/104_ssh_fxp_name.rb +48 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/105_ssh_fxp_attrs.rb +28 -0
- data/lib/hrr_rb_sftp/protocol/version1/packets/packet.rb +57 -0
- data/lib/hrr_rb_sftp/protocol/version2.rb +11 -3
- data/lib/hrr_rb_sftp/protocol/version2/data_types.rb +13 -0
- data/lib/hrr_rb_sftp/protocol/version2/packets.rb +14 -0
- data/lib/hrr_rb_sftp/protocol/version2/packets/018_ssh_fxp_rename.rb +91 -0
- data/lib/hrr_rb_sftp/protocol/version3.rb +12 -3
- data/lib/hrr_rb_sftp/protocol/version3/data_types.rb +13 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions.rb +94 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/extension.rb +58 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/fsync_at_openssh_com.rb +59 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/hardlink_at_openssh_com.rb +84 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/lsetstat_at_openssh_com.rb +132 -0
- data/lib/hrr_rb_sftp/protocol/version3/extensions/posix_rename_at_openssh_com.rb +76 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets.rb +19 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets/014_ssh_fxp_mkdir.rb +75 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets/019_ssh_fxp_readlink.rb +76 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets/020_ssh_fxp_symlink.rb +76 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets/101_ssh_fxp_status.rb +25 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets/200_ssh_fxp_extended.rb +95 -0
- data/lib/hrr_rb_sftp/protocol/version3/packets/201_ssh_fxp_extended_reply.rb +60 -0
- data/lib/hrr_rb_sftp/receiver.rb +17 -2
- data/lib/hrr_rb_sftp/sender.rb +15 -1
- data/lib/hrr_rb_sftp/server.rb +43 -12
- data/lib/hrr_rb_sftp/version.rb +5 -1
- metadata +54 -47
- data/lib/hrr_rb_sftp/protocol/common/data_type.rb +0 -15
- data/lib/hrr_rb_sftp/protocol/common/data_type/byte.rb +0 -22
- data/lib/hrr_rb_sftp/protocol/common/data_type/extension_pair.rb +0 -23
- data/lib/hrr_rb_sftp/protocol/common/data_type/extension_pairs.rb +0 -24
- data/lib/hrr_rb_sftp/protocol/common/data_type/string.rb +0 -24
- data/lib/hrr_rb_sftp/protocol/common/data_type/uint32.rb +0 -22
- data/lib/hrr_rb_sftp/protocol/common/data_type/uint64.rb +0 -22
- data/lib/hrr_rb_sftp/protocol/common/packet.rb +0 -11
- data/lib/hrr_rb_sftp/protocol/common/packet/001_ssh_fxp_init.rb +0 -18
- data/lib/hrr_rb_sftp/protocol/common/packet/002_ssh_fxp_version.rb +0 -19
- data/lib/hrr_rb_sftp/protocol/common/packetable.rb +0 -72
- data/lib/hrr_rb_sftp/protocol/version1/data_type.rb +0 -11
- data/lib/hrr_rb_sftp/protocol/version1/data_type/attrs.rb +0 -54
- data/lib/hrr_rb_sftp/protocol/version1/packet.rb +0 -29
- data/lib/hrr_rb_sftp/protocol/version1/packet/004_ssh_fxp_close.rb +0 -44
- data/lib/hrr_rb_sftp/protocol/version1/packet/005_ssh_fxp_read.rb +0 -53
- data/lib/hrr_rb_sftp/protocol/version1/packet/006_ssh_fxp_write.rb +0 -46
- data/lib/hrr_rb_sftp/protocol/version1/packet/009_ssh_fxp_setstat.rb +0 -63
- data/lib/hrr_rb_sftp/protocol/version1/packet/010_ssh_fxp_fsetstat.rb +0 -48
- data/lib/hrr_rb_sftp/protocol/version1/packet/016_ssh_fxp_realpath.rb +0 -30
- data/lib/hrr_rb_sftp/protocol/version1/packet/101_ssh_fxp_status.rb +0 -29
- data/lib/hrr_rb_sftp/protocol/version1/packet/102_ssh_fxp_handle.rb +0 -19
- data/lib/hrr_rb_sftp/protocol/version1/packet/103_ssh_fxp_data.rb +0 -19
- data/lib/hrr_rb_sftp/protocol/version1/packet/104_ssh_fxp_name.rb +0 -33
- data/lib/hrr_rb_sftp/protocol/version1/packet/105_ssh_fxp_attrs.rb +0 -19
- data/lib/hrr_rb_sftp/protocol/version2/data_type.rb +0 -9
- data/lib/hrr_rb_sftp/protocol/version2/packet.rb +0 -11
- data/lib/hrr_rb_sftp/protocol/version2/packet/018_ssh_fxp_rename.rb +0 -70
- data/lib/hrr_rb_sftp/protocol/version3/data_type.rb +0 -9
- data/lib/hrr_rb_sftp/protocol/version3/packet.rb +0 -16
- data/lib/hrr_rb_sftp/protocol/version3/packet/014_ssh_fxp_mkdir.rb +0 -58
- data/lib/hrr_rb_sftp/protocol/version3/packet/019_ssh_fxp_readlink.rb +0 -57
- data/lib/hrr_rb_sftp/protocol/version3/packet/020_ssh_fxp_symlink.rb +0 -58
- data/lib/hrr_rb_sftp/protocol/version3/packet/101_ssh_fxp_status.rb +0 -31
- data/lib/hrr_rb_sftp/protocol/version3/packet/200_ssh_fxp_extended.rb +0 -34
- data/lib/hrr_rb_sftp/protocol/version3/packet/201_ssh_fxp_extended_reply.rb +0 -23
@@ -1,15 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
require "hrr_rb_sftp/protocol/common/data_type/byte"
|
11
|
-
require "hrr_rb_sftp/protocol/common/data_type/uint32"
|
12
|
-
require "hrr_rb_sftp/protocol/common/data_type/uint64"
|
13
|
-
require 'hrr_rb_sftp/protocol/common/data_type/string'
|
14
|
-
require 'hrr_rb_sftp/protocol/common/data_type/extension_pair'
|
15
|
-
require 'hrr_rb_sftp/protocol/common/data_type/extension_pairs'
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
module Byte
|
6
|
-
def self.encode arg
|
7
|
-
case arg
|
8
|
-
when 0x00..0xff
|
9
|
-
[arg].pack("C")
|
10
|
-
else
|
11
|
-
raise ArgumentError, "must be in #{0x00}..#{0xff}, but got #{arg.inspect}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.decode io
|
16
|
-
io.read(1).unpack("C")[0]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
module ExtensionPair
|
6
|
-
def self.encode arg
|
7
|
-
unless arg.kind_of? ::Hash
|
8
|
-
raise ArgumentError, "must be a kind of Hash, but got #{arg.inspect}"
|
9
|
-
end
|
10
|
-
DataType::String.encode(arg[:"extension-name"]) + DataType::String.encode(arg[:"extension-data"])
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.decode io
|
14
|
-
{
|
15
|
-
:"extension-name" => DataType::String.decode(io),
|
16
|
-
:"extension-data" => DataType::String.decode(io),
|
17
|
-
}
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
module ExtensionPairs
|
6
|
-
def self.encode arg
|
7
|
-
unless arg.kind_of? ::Array
|
8
|
-
raise ArgumentError, "must be a kind of Array, but got #{arg.inspect}"
|
9
|
-
end
|
10
|
-
arg.map{|arg| ExtensionPair.encode(arg)}.join
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.decode io
|
14
|
-
extension_pairs = Array.new
|
15
|
-
until io.eof?
|
16
|
-
extension_pairs.push ExtensionPair.decode(io)
|
17
|
-
end
|
18
|
-
extension_pairs
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
module String
|
6
|
-
def self.encode arg
|
7
|
-
unless arg.kind_of? ::String
|
8
|
-
raise ArgumentError, "must be a kind of String, but got #{arg.inspect}"
|
9
|
-
end
|
10
|
-
if arg.bytesize > 0xffff_ffff
|
11
|
-
raise ArgumentError, "must be shorter than or equal to #{0xffff_ffff}, but got length #{arg.bytesize}"
|
12
|
-
end
|
13
|
-
[arg.bytesize, arg].pack("Na*")
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.decode io
|
17
|
-
length = io.read(4).unpack("N")[0]
|
18
|
-
io.read(length).unpack("a*")[0].force_encoding(Encoding::UTF_8)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
module Uint32
|
6
|
-
def self.encode arg
|
7
|
-
case arg
|
8
|
-
when 0x0000_0000..0xffff_ffff
|
9
|
-
[arg].pack("N")
|
10
|
-
else
|
11
|
-
raise ArgumentError, "must be in #{0x0000_0000}..#{0xffff_ffff}, but got #{arg.inspect}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.decode io
|
16
|
-
io.read(4).unpack("N")[0]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module DataType
|
5
|
-
module Uint64
|
6
|
-
def self.encode arg
|
7
|
-
case arg
|
8
|
-
when 0x0000_0000_0000_0000..0xffff_ffff_ffff_ffff
|
9
|
-
[arg >> 32].pack("N") + [arg & 0x0000_0000_ffff_ffff].pack("N")
|
10
|
-
else
|
11
|
-
raise ArgumentError, "must be in #{0x0000_0000_0000_0000}..#{0xffff_ffff_ffff_ffff}, but got #{arg.inspect}"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.decode io
|
16
|
-
(io.read(4).unpack("N")[0] << 32) + (io.read(4).unpack("N")[0])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module Packet
|
5
|
-
class SSH_FXP_VERSION
|
6
|
-
include Packetable
|
7
|
-
|
8
|
-
TYPE = 2
|
9
|
-
|
10
|
-
FORMAT = [
|
11
|
-
[DataType::Byte, :"type" ],
|
12
|
-
[DataType::Uint32, :"version" ],
|
13
|
-
[DataType::ExtensionPairs, :"extensions"],
|
14
|
-
]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
module Common
|
4
|
-
module Packetable
|
5
|
-
include Loggable
|
6
|
-
|
7
|
-
def initialize handles, logger: nil
|
8
|
-
self.logger = logger
|
9
|
-
|
10
|
-
@handles = handles
|
11
|
-
end
|
12
|
-
|
13
|
-
def encode packet
|
14
|
-
log_debug { 'encoding packet: ' + packet.inspect }
|
15
|
-
format = common_format + conditional_format(packet)
|
16
|
-
format.map{ |data_type, field_name|
|
17
|
-
begin
|
18
|
-
field_value = packet[field_name]
|
19
|
-
data_type.encode field_value
|
20
|
-
rescue => e
|
21
|
-
log_debug { "'field_name', 'field_value': #{field_name.inspect}, #{field_value.inspect}" }
|
22
|
-
raise e
|
23
|
-
end
|
24
|
-
}.join
|
25
|
-
end
|
26
|
-
|
27
|
-
def decode payload
|
28
|
-
payload_io = StringIO.new payload
|
29
|
-
format = common_format
|
30
|
-
decoded_packet = decode_recursively(payload_io).inject(Hash.new){ |h, (k, v)| h.update({k => v}) }
|
31
|
-
log_debug { 'decoded packet: ' + decoded_packet.inspect }
|
32
|
-
decoded_packet
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def common_format
|
38
|
-
self.class::FORMAT
|
39
|
-
end
|
40
|
-
|
41
|
-
def conditional_format packet
|
42
|
-
return [] unless self.class.const_defined? :CONDITIONAL_FORMAT
|
43
|
-
packet.inject([]){ |a, (field_name, field_value)|
|
44
|
-
a + (self.class::CONDITIONAL_FORMAT.fetch(field_name, {})[field_value] || [])
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def decode_recursively payload_io, packet=nil
|
49
|
-
if packet.class == Array and packet.size == 0
|
50
|
-
[]
|
51
|
-
else
|
52
|
-
format = case packet
|
53
|
-
when nil
|
54
|
-
common_format
|
55
|
-
when Array
|
56
|
-
conditional_format(packet)
|
57
|
-
end
|
58
|
-
decoded_packet = format.map{ |data_type, field_name|
|
59
|
-
begin
|
60
|
-
[field_name, data_type.decode(payload_io)]
|
61
|
-
rescue => e
|
62
|
-
log_debug { "'field_name': #{field_name.inspect}" }
|
63
|
-
raise e
|
64
|
-
end
|
65
|
-
}
|
66
|
-
decoded_packet + decode_recursively(payload_io, decoded_packet)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
class Version1
|
4
|
-
module DataType
|
5
|
-
class Attrs
|
6
|
-
SSH_FILEXFER_ATTR_SIZE = 0x00000001
|
7
|
-
SSH_FILEXFER_ATTR_UIDGID = 0x00000002
|
8
|
-
SSH_FILEXFER_ATTR_PERMISSIONS = 0x00000004
|
9
|
-
SSH_FILEXFER_ATTR_ACMODTIME = 0x00000008
|
10
|
-
SSH_FILEXFER_ATTR_EXTENDED = 0x80000000
|
11
|
-
|
12
|
-
def self.encode arg
|
13
|
-
unless arg.kind_of? ::Hash
|
14
|
-
raise ArgumentError, "must be a kind of Hash, but got #{arg.inspect}"
|
15
|
-
end
|
16
|
-
|
17
|
-
flags = 0
|
18
|
-
flags |= SSH_FILEXFER_ATTR_SIZE if arg.has_key?(:"size")
|
19
|
-
flags |= SSH_FILEXFER_ATTR_UIDGID if arg.has_key?(:"uid") && arg.has_key?(:"gid")
|
20
|
-
flags |= SSH_FILEXFER_ATTR_PERMISSIONS if arg.has_key?(:"permissions")
|
21
|
-
flags |= SSH_FILEXFER_ATTR_ACMODTIME if arg.has_key?(:"atime") && arg.has_key?(:"mtime")
|
22
|
-
flags |= SSH_FILEXFER_ATTR_EXTENDED if arg.has_key?(:"extensions")
|
23
|
-
|
24
|
-
payload = DataType::Uint32.encode flags
|
25
|
-
payload += DataType::Uint64.encode arg[:"size"] unless (flags & SSH_FILEXFER_ATTR_SIZE).zero?
|
26
|
-
payload += DataType::Uint32.encode arg[:"uid"] unless (flags & SSH_FILEXFER_ATTR_UIDGID).zero?
|
27
|
-
payload += DataType::Uint32.encode arg[:"gid"] unless (flags & SSH_FILEXFER_ATTR_UIDGID).zero?
|
28
|
-
payload += DataType::Uint32.encode arg[:"permissions"] unless (flags & SSH_FILEXFER_ATTR_PERMISSIONS).zero?
|
29
|
-
payload += DataType::Uint32.encode arg[:"atime"] unless (flags & SSH_FILEXFER_ATTR_ACMODTIME).zero?
|
30
|
-
payload += DataType::Uint32.encode arg[:"mtime"] unless (flags & SSH_FILEXFER_ATTR_ACMODTIME).zero?
|
31
|
-
payload += DataType::Uint32.encode arg[:"extensions"].size unless (flags & SSH_FILEXFER_ATTR_EXTENDED).zero?
|
32
|
-
payload += DataType::ExtensionPairs.encode arg[:"extensions"] unless (flags & SSH_FILEXFER_ATTR_EXTENDED).zero?
|
33
|
-
payload
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.decode io
|
37
|
-
attrs = Hash.new
|
38
|
-
flags = DataType::Uint32.decode(io)
|
39
|
-
attrs[:"size"] = DataType::Uint64.decode(io) unless (flags & SSH_FILEXFER_ATTR_SIZE).zero?
|
40
|
-
attrs[:"uid"] = DataType::Uint32.decode(io) unless (flags & SSH_FILEXFER_ATTR_UIDGID).zero?
|
41
|
-
attrs[:"gid"] = DataType::Uint32.decode(io) unless (flags & SSH_FILEXFER_ATTR_UIDGID).zero?
|
42
|
-
attrs[:"permissions"] = DataType::Uint32.decode(io) unless (flags & SSH_FILEXFER_ATTR_PERMISSIONS).zero?
|
43
|
-
attrs[:"atime"] = DataType::Uint32.decode(io) unless (flags & SSH_FILEXFER_ATTR_ACMODTIME).zero?
|
44
|
-
attrs[:"mtime"] = DataType::Uint32.decode(io) unless (flags & SSH_FILEXFER_ATTR_ACMODTIME).zero?
|
45
|
-
extended_count = DataType::Uint32.decode(io) unless (flags & SSH_FILEXFER_ATTR_EXTENDED).zero?
|
46
|
-
attrs[:"extensions"] = Array.new(extended_count){DataType::ExtensionPair.decode(io)} unless (flags & SSH_FILEXFER_ATTR_EXTENDED).zero?
|
47
|
-
attrs
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
class Version1
|
4
|
-
module Packet
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
require "hrr_rb_sftp/protocol/version1/packet/003_ssh_fxp_open"
|
11
|
-
require "hrr_rb_sftp/protocol/version1/packet/004_ssh_fxp_close"
|
12
|
-
require "hrr_rb_sftp/protocol/version1/packet/005_ssh_fxp_read"
|
13
|
-
require "hrr_rb_sftp/protocol/version1/packet/006_ssh_fxp_write"
|
14
|
-
require "hrr_rb_sftp/protocol/version1/packet/007_ssh_fxp_lstat"
|
15
|
-
require "hrr_rb_sftp/protocol/version1/packet/008_ssh_fxp_fstat"
|
16
|
-
require "hrr_rb_sftp/protocol/version1/packet/009_ssh_fxp_setstat"
|
17
|
-
require "hrr_rb_sftp/protocol/version1/packet/010_ssh_fxp_fsetstat"
|
18
|
-
require "hrr_rb_sftp/protocol/version1/packet/011_ssh_fxp_opendir"
|
19
|
-
require "hrr_rb_sftp/protocol/version1/packet/012_ssh_fxp_readdir"
|
20
|
-
require "hrr_rb_sftp/protocol/version1/packet/013_ssh_fxp_remove"
|
21
|
-
require "hrr_rb_sftp/protocol/version1/packet/014_ssh_fxp_mkdir"
|
22
|
-
require "hrr_rb_sftp/protocol/version1/packet/015_ssh_fxp_rmdir"
|
23
|
-
require "hrr_rb_sftp/protocol/version1/packet/016_ssh_fxp_realpath"
|
24
|
-
require "hrr_rb_sftp/protocol/version1/packet/017_ssh_fxp_stat"
|
25
|
-
require "hrr_rb_sftp/protocol/version1/packet/101_ssh_fxp_status"
|
26
|
-
require "hrr_rb_sftp/protocol/version1/packet/102_ssh_fxp_handle"
|
27
|
-
require "hrr_rb_sftp/protocol/version1/packet/103_ssh_fxp_data"
|
28
|
-
require "hrr_rb_sftp/protocol/version1/packet/104_ssh_fxp_name"
|
29
|
-
require "hrr_rb_sftp/protocol/version1/packet/105_ssh_fxp_attrs"
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
class Version1
|
4
|
-
module Packet
|
5
|
-
class SSH_FXP_CLOSE
|
6
|
-
include Common::Packetable
|
7
|
-
|
8
|
-
TYPE = 4
|
9
|
-
|
10
|
-
FORMAT = [
|
11
|
-
[DataType::Byte, :"type" ],
|
12
|
-
[DataType::Uint32, :"request-id"],
|
13
|
-
[DataType::String, :"handle" ],
|
14
|
-
]
|
15
|
-
|
16
|
-
def respond_to request
|
17
|
-
begin
|
18
|
-
raise "Specified handle does not exist" unless @handles.has_key?(request[:"handle"])
|
19
|
-
handle = request[:"handle"]
|
20
|
-
@handles[handle].close rescue nil
|
21
|
-
@handles.delete(handle)
|
22
|
-
{
|
23
|
-
:"type" => SSH_FXP_STATUS::TYPE,
|
24
|
-
:"request-id" => request[:"request-id"],
|
25
|
-
:"code" => SSH_FXP_STATUS::SSH_FX_OK,
|
26
|
-
:"error message" => "Success",
|
27
|
-
:"language tag" => "",
|
28
|
-
}
|
29
|
-
rescue => e
|
30
|
-
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
31
|
-
{
|
32
|
-
:"type" => SSH_FXP_STATUS::TYPE,
|
33
|
-
:"request-id" => request[:"request-id"],
|
34
|
-
:"code" => SSH_FXP_STATUS::SSH_FX_FAILURE,
|
35
|
-
:"error message" => e.message,
|
36
|
-
:"language tag" => "",
|
37
|
-
}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module HrrRbSftp
|
2
|
-
class Protocol
|
3
|
-
class Version1
|
4
|
-
module Packet
|
5
|
-
class SSH_FXP_READ
|
6
|
-
include Common::Packetable
|
7
|
-
|
8
|
-
TYPE = 5
|
9
|
-
|
10
|
-
FORMAT = [
|
11
|
-
[DataType::Byte, :"type" ],
|
12
|
-
[DataType::Uint32, :"request-id"],
|
13
|
-
[DataType::String, :"handle" ],
|
14
|
-
[DataType::Uint64, :"offset" ],
|
15
|
-
[DataType::Uint32, :"len" ],
|
16
|
-
]
|
17
|
-
|
18
|
-
def respond_to request
|
19
|
-
begin
|
20
|
-
raise "Specified handle does not exist" unless @handles.has_key?(request[:"handle"])
|
21
|
-
file = @handles[request[:"handle"]]
|
22
|
-
file.pos = request[:"offset"]
|
23
|
-
unless file.eof?
|
24
|
-
{
|
25
|
-
:"type" => SSH_FXP_DATA::TYPE,
|
26
|
-
:"request-id" => request[:"request-id"],
|
27
|
-
:"data" => file.read(request[:"len"]),
|
28
|
-
}
|
29
|
-
else
|
30
|
-
{
|
31
|
-
:"type" => SSH_FXP_STATUS::TYPE,
|
32
|
-
:"request-id" => request[:"request-id"],
|
33
|
-
:"code" => SSH_FXP_STATUS::SSH_FX_EOF,
|
34
|
-
:"error message" => "End of file",
|
35
|
-
:"language tag" => "",
|
36
|
-
}
|
37
|
-
end
|
38
|
-
rescue => e
|
39
|
-
log_error { [e.backtrace[0], ": ", e.message, " (", e.class.to_s, ")\n\t", e.backtrace[1..-1].join("\n\t")].join }
|
40
|
-
{
|
41
|
-
:"type" => SSH_FXP_STATUS::TYPE,
|
42
|
-
:"request-id" => request[:"request-id"],
|
43
|
-
:"code" => SSH_FXP_STATUS::SSH_FX_FAILURE,
|
44
|
-
:"error message" => e.message,
|
45
|
-
:"language tag" => "",
|
46
|
-
}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|