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

Inherits:
Object
  • Object
show all
Includes:
Constants, Constants::PacketTypes, Net::SSH::Loggable
Defined in:
lib/net/sftp/protocol/base.rb

Overview

The abstract superclass of the specific implementations for each supported SFTP protocol version. It implements general packet parsing logic, and provides a way for subclasses to send requests.

Direct Known Subclasses

V01::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 collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Base

Create a new instance of a protocol driver, servicing the given session.



18
19
20
21
22
# File 'lib/net/sftp/protocol/base.rb', line 18

def initialize(session)
  @session = session
  self.logger = session.logger
  @request_id_counter = -1
end

Instance Attribute Details

#sessionObject (readonly)

The SFTP session object that acts as client to this protocol instance



15
16
17
# File 'lib/net/sftp/protocol/base.rb', line 15

def session
  @session
end

Instance Method Details

#parse(packet) ⇒ Object

Attept to parse the given packet. If the packet is of an unsupported type, an exception will be raised. Returns the parsed data as a hash (the keys in the hash are packet-type specific).



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

def parse(packet)
  case packet.type
  when FXP_STATUS then parse_status_packet(packet)
  when FXP_HANDLE then parse_handle_packet(packet)
  when FXP_DATA   then parse_data_packet(packet)
  when FXP_NAME   then parse_name_packet(packet)
  when FXP_ATTRS  then parse_attrs_packet(packet)
  else raise NotImplementedError, "unknown packet type: #{packet.type}"
  end
end