Class Net::SFTP::Session
In: lib/net/sftp/session.rb
Parent: Object

Represents a single SFTP session, running atop an SSH session.

Methods

Included Modules

Protocol::Constants

Attributes

status  [RW]  The status of the last synchronously executed operation. This is either nil, or an object that responds to :code, :message, and :language.

Public Class methods

Create a new SFTP session on top of the given SSH session.

Public Instance methods

Return the underlying SSH channel that supports this SFTP connection. Useful for adding custom callbacks for some events, or for accessing the underlying connection beneath the channel.

Closes the underlying SSH connection.

Closes the SFTP connection, but leaves the SSH connection open.

Waits for the underlying driver to reach a state of :open (or :closed). This makes it easier to use the SFTP routines synchronously without using the block form:

  sftp = Net::SFTP::Session.new( ssh_session )
  sftp.connect
  puts sftp.realpath( "." )

Without the call to connect, the call to realpath would fail because the SFTP protocol has not yet been negotiated and no underlying driver has been selected.

If no block is given, it returns self, so it can be chained easily to other method calls. If a block is given, the session is yielded to the block as soon as the driver successfully reports it’s state as open, with the session’s channel being closed automatically when the block finishes.

  require 'net/ssh'
  require 'net/sftp'

  Net::SSH.start( 'localhost' ) do |session|
    session.sftp.connect do |sftp|
      puts sftp.realpath( "." )
    end
  end

Invoked by the underlying SFTP protocol layer when a SFTP attrs packet is received.

Invoked by the underlying SFTP protocol layer when a SFTP data packet is received.

Invoked by the underlying SFTP protocol layer when a SFTP handle packet is received.

Invoked by the underlying SFTP protocol layer when a SFTP name packet is received.

Invoked by the underlying SFTP protocol layer when a SFTP status packet is received.

Retrieves the given remote file to the given local path. This will overwrite any file at the local path name. The remote file must exist.

Delegates to Net::SSH::Session#loop. Causes the underlying SSH connection to process events as long as the given block returns true, or (if no block is given) until there are no more open channels.

Delegates the message to the operation that has been registered with the given name. If no such operation exists, control is passed to the superclass’ implementation of method_missing.

Opens the given remote file and returns a handle to it, which may be used with other operations (read, write, etc.). If a block is given, the handle will be yielded to it and closed when the block finishes, otherwise the handle will be returned. If the flags parameter is a numeric value, it must be a combination of IO constants, otherwise, it should be a string such as given to File.open.

This stores the given local file at the given remote path. This will overwrite any file at the remote path name. The local file must exist.

Registers the given handler with the given request id. This is used internally by the operations, so that the session knows who to delegate a response to that has been received from the server.

Returns true if the object responds to the given symbol, or if there is an operation registered under the given symbol.

Return the state of the SFTP connection. (See Net::SFTP::Protocol::Driver#state.)

Returns true if the underlying driver responds to the given symbol. This can be used by clients to determine whether the SFTP protocol version in use supports a particular operation.

[Validate]