Class Net::SFTP::Protocol::Driver
In: lib/net/sftp/protocol/driver.rb
Parent: Object

This is the driver object for the SFTP protocol. It manages the SSH channel used to communicate with the server, as well as the negotiation of the protocol. The operations themselves are specific to the protocol version in use, and are handled by protocol-version-specific dispatcher objects.

Methods

Included Modules

Constants

Attributes

channel  [R]  The underlying SSH channel supporting this SFTP connection.
state  [R]  The current state of the driver. This will be one of unconfirmed, init, version, open, or closed.

Public Class methods

Create a new SFTP protocol driver object on the given SSH connection. buffers is a reference to a buffer factory, version is the highest supported SFTP protocol version, dispatchers is a Proc object that returns a dispatcher instance for a specific protocol version, and log is a logger instance.

The new protocol driver will be in an unconfirmed state, initially. When the server validates the requested channel, the driver goes to the init state, and requests the SFTP subsystem. When the subsystem has been accepted, the driver sends its supported protocol version to the server, and goes to the version state. Lastly, when the server responds with its supported protocol version and the version to use has been successfully negotiated, the driver will go to the open state, after which SFTP operations may be successfully performed on the driver.

Public Instance methods

Closes the underlying SSH channel that the SFTP session uses to communicate with the server. This moves the driver to the closed state. If the driver is already closed, this does nothing.

The callback used internally to indicate that the requested channel has been confirmed. This will request the SFTP subsystem, register some request callbacks, and move the driver‘s state to init. This may only be called when the driver‘s state is unconfirmed.

This is called internally when a data packet is received from the server. All SFTP packets are transfered as SSH data packets, so this parses the data packet to determine the SFTP packet type, and then sends the contents on to the active dispatcher for further processing. This routine correctly handles SFTP packets that span multiple SSH data packets.

The callback used internally to indicate that the SFTP subsystem was successfully requested. This may only be called when the driver‘s state is init. It sends an INIT packet containing the highest supported SFTP protocol version to the server, and moves the driver‘s state to version.

This is used internally to indicate that a VERSION packet was received from the server. This may only be called when the driver‘s state is version. It determines the highest possible protocol version supported by both the client and the server, selects the dispatcher that handles that protocol version, moves the state to open, and then invokes the on_open callback (if one was registered).

Delegates missing methods to the current dispatcher (if the state is open). This allows clients to register callbacks for the supported operations of the negotiated protocol version.

Returns the next available request id in a thread-safe manner. The request-id is used to identify packets associated with request sequences.

Specify the callback to invoke when the session has been successfully opened (i.e., once the driver‘s state has moved to open). The callback should accept a single parameter—the driver itself.

Returns true if the driver responds to the given message, or if the state is open and the active dispatcher responds to the given message.

A convenience method for sending an SFTP packet of the given type, with the given payload. This repackages the data as an SSH data packet and sends it across the channel.

[Validate]