Class: Net::SFTP::Session

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

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

### Methods

channel close close_channel connect do_attrs do_data do_handle do_name do_status get_file loop method_missing new open_handle put_file register respond_to? state support?

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

new( session ) {|self| ...}

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

### Public Instance methods

channel()

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.

close()

Closes the underlying SSH connection.

close_channel()

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

connect() {|self| ...}

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

do_attrs( driver, id, attributes )

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

do_data( driver, id, data )

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

do_handle( driver, id, handle )

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

do_name( driver, id, items )

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

do_status( driver, id, code, message, language )

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

get_file( remote_path, local_path )

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.

loop( &block )

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.

method_missing( sym, *args, &block )

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.

open_handle( path, flags=IO::RDONLY, mode=0660 ) {|handle| ...}

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.

put_file( local_path, remote_path )

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.

register( id, handler )

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.

respond_to?( sym )

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

state()

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

support?( sym )

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]