Sha256: f704ca8d6c959b411091756b46e2e0e0bcacb9a7d1a6e5ead50c77da55f16be4

Contents?: true

Size: 1.71 KB

Versions: 167

Compression:

Stored size: 1.71 KB

Contents

require 'net/ssh/loggable'
require 'net/sftp/constants'

module Net; module SFTP; module Protocol

  # 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.
  class Base
    include Net::SSH::Loggable
    include Net::SFTP::Constants
    include Net::SFTP::Constants::PacketTypes

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

    # Create a new instance of a protocol driver, servicing the given session.
    def initialize(session)
      @session = session
      self.logger = session.logger
      @request_id_counter = -1
    end

    # 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).
    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

    private

      # Send a new packet of the given type, and with the given data arguments.
      # A new request identifier will be allocated to this request, and will
      # be returned.
      def send_request(type, *args)
        @request_id_counter += 1
        session.send_packet(type, :long, @request_id_counter, *args)
        return @request_id_counter
      end
  end

end; end; end

Version data entries

167 entries across 129 versions & 10 rubygems

Version Path
net-sftp-backports-4.0.8.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.7.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.6.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.5.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.4.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.3.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.2.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.1.backports lib/net/sftp/protocol/base.rb
net-sftp-backports-4.0.0.backports lib/net/sftp/protocol/base.rb
net-sftp-4.0.0 lib/net/sftp/protocol/base.rb
net-sftp-4.0.0.rc1 lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/net-sftp-3.0.0/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/net-sftp-3.0.0/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-3.0.0/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/net-sftp-3.0.0/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-3.0.0/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-3.0.0/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-2.1.2/lib/net/sftp/protocol/base.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/net-sftp-2.1.2/lib/net/sftp/protocol/base.rb
net-sftp-3.0.0 lib/net/sftp/protocol/base.rb