Class: Net::SFTP::Protocol::V04::Base

Inherits:
Net::SFTP::Protocol::V03::Base show all
Defined in:
lib/net/sftp/protocol/04/base.rb

Overview

Wraps the low-level SFTP calls for version 4 of the SFTP protocol. Also implements the updated FXP_NAME packet parsing as mandated by v4 of the protocol.

None of these protocol methods block–all of them return immediately, requiring the SSH event loop to be run while the server response is pending.

You will almost certainly never need to use this driver directly. Please see Net::SFTP::Session for the recommended interface.

Direct Known Subclasses

Net::SFTP::Protocol::V05::Base

Constant Summary

Constants included from Constants::PacketTypes

Constants::PacketTypes::FXP_ATTRS, Constants::PacketTypes::FXP_BLOCK, Constants::PacketTypes::FXP_CLOSE, Constants::PacketTypes::FXP_DATA, Constants::PacketTypes::FXP_EXTENDED, Constants::PacketTypes::FXP_EXTENDED_REPLY, Constants::PacketTypes::FXP_FSETSTAT, Constants::PacketTypes::FXP_FSTAT, Constants::PacketTypes::FXP_HANDLE, Constants::PacketTypes::FXP_INIT, Constants::PacketTypes::FXP_LINK, Constants::PacketTypes::FXP_LSTAT, Constants::PacketTypes::FXP_MKDIR, Constants::PacketTypes::FXP_NAME, Constants::PacketTypes::FXP_OPEN, Constants::PacketTypes::FXP_OPENDIR, Constants::PacketTypes::FXP_READ, Constants::PacketTypes::FXP_READDIR, Constants::PacketTypes::FXP_READLINK, Constants::PacketTypes::FXP_REALPATH, Constants::PacketTypes::FXP_REMOVE, Constants::PacketTypes::FXP_RENAME, Constants::PacketTypes::FXP_RMDIR, Constants::PacketTypes::FXP_SETSTAT, Constants::PacketTypes::FXP_STAT, Constants::PacketTypes::FXP_STATUS, Constants::PacketTypes::FXP_SYMLINK, Constants::PacketTypes::FXP_UNBLOCK, Constants::PacketTypes::FXP_VERSION, Constants::PacketTypes::FXP_WRITE

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods inherited from Net::SFTP::Protocol::V03::Base

#readlink, #symlink

Methods inherited from Net::SFTP::Protocol::V02::Base

#rename

Methods inherited from Net::SFTP::Protocol::V01::Base

#block, #close, #fsetstat, #link, #mkdir, #open, #opendir, #parse_attrs_packet, #parse_data_packet, #parse_handle_packet, #parse_status_packet, #read, #readdir, #readlink, #realpath, #remove, #rename, #rmdir, #setstat, #symlink, #unblock, #write

Methods inherited from Base

#initialize, #parse

Constructor Details

This class inherits a constructor from Net::SFTP::Protocol::Base

Instance Method Details

#fstat(handle, flags = nil) ⇒ Object

Sends a FXP_FSTAT packet to the server for the given path, and with the given flags. If flags is nil, it defaults to F_SIZE | F_PERMISSIONS | F_ACCESSTIME | F_CREATETIME | F_MODIFYTIME | F_ACL | F_OWNERGROUP | F_SUBSECOND_TIMES | F_EXTENDED (see Net::SFTP::Protocol::V04::Attributes for those constants).



63
64
65
# File 'lib/net/sftp/protocol/04/base.rb', line 63

def fstat(handle, flags=nil)
  send_request(FXP_FSTAT, :string, handle, :long, flags || DEFAULT_FLAGS)
end

#lstat(path, flags = nil) ⇒ Object

Sends a FXP_LSTAT packet to the server for the given path, and with the given flags. If flags is nil, it defaults to F_SIZE | F_PERMISSIONS | F_ACCESSTIME | F_CREATETIME | F_MODIFYTIME | F_ACL | F_OWNERGROUP | F_SUBSECOND_TIMES | F_EXTENDED (see Net::SFTP::Protocol::V04::Attributes for those constants).



54
55
56
# File 'lib/net/sftp/protocol/04/base.rb', line 54

def lstat(path, flags=nil)
  send_request(FXP_LSTAT, :string, path, :long, flags || DEFAULT_FLAGS)
end

#parse_name_packet(packet) ⇒ Object

As of v4 of the SFTP protocol, the “longname” member was removed from the FXP_NAME structure. This method is essentially the same as the previous implementation, but omits longname.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/net/sftp/protocol/04/base.rb', line 28

def parse_name_packet(packet)
  names = []

  packet.read_long.times do
    filename = packet.read_string
    attrs    = attribute_factory.from_buffer(packet)
    names   << name_factory.new(filename, attrs)
  end

  { :names => names }
end

#stat(path, flags = nil) ⇒ Object

Sends a FXP_STAT packet to the server for the given path, and with the given flags. If flags is nil, it defaults to F_SIZE | F_PERMISSIONS | F_ACCESSTIME | F_CREATETIME | F_MODIFYTIME | F_ACL | F_OWNERGROUP | F_SUBSECOND_TIMES | F_EXTENDED (see Net::SFTP::Protocol::V04::Attributes for those constants).



45
46
47
# File 'lib/net/sftp/protocol/04/base.rb', line 45

def stat(path, flags=nil)
  send_request(FXP_STAT, :string, path, :long, flags || DEFAULT_FLAGS)
end

#versionObject

Returns the protocol version implemented by this driver. (4, in this case)



21
22
23
# File 'lib/net/sftp/protocol/04/base.rb', line 21

def version
  4
end