Module: Net::SFTP

### Home Classes Methods

### In Files

- lib/net/sftp.rb
- lib/net/sftp/constants.rb
- lib/net/sftp/errors.rb
- lib/net/sftp/operations/dir.rb
- lib/net/sftp/operations/download.rb
- lib/net/sftp/operations/file.rb
- lib/net/sftp/operations/file_factory.rb
- lib/net/sftp/operations/upload.rb
- lib/net/sftp/packet.rb
- lib/net/sftp/protocol.rb
- lib/net/sftp/protocol/01/attributes.rb
- lib/net/sftp/protocol/01/base.rb
- lib/net/sftp/protocol/01/name.rb
- lib/net/sftp/protocol/02/base.rb
- lib/net/sftp/protocol/03/base.rb
- lib/net/sftp/protocol/04/attributes.rb
- lib/net/sftp/protocol/04/base.rb
- lib/net/sftp/protocol/04/name.rb
- lib/net/sftp/protocol/05/base.rb
- lib/net/sftp/protocol/06/attributes.rb
- lib/net/sftp/protocol/06/base.rb
- lib/net/sftp/protocol/base.rb
- lib/net/sftp/request.rb
- lib/net/sftp/response.rb
- lib/net/sftp/session.rb
- lib/net/sftp/version.rb

### Namespace

- MODULE Net::SFTP::Constants
- MODULE Net::SFTP::Operations
- MODULE Net::SFTP::Protocol
- CLASS Net::SFTP::Exception
- CLASS Net::SFTP::Packet
- CLASS Net::SFTP::Request
- CLASS Net::SFTP::Response
- CLASS Net::SFTP::Session
- CLASS Net::SFTP::StatusException
- CLASS Net::SFTP::Version

### Methods

- ::start

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Net
- Net::SFTP
- Net::SFTP::Constants
- Net::SFTP::Constants::ACE
- Net::SFTP::Constants::ACE::Flag
- Net::SFTP::Constants::ACE::Mask
- Net::SFTP::Constants::ACE::Type
- Net::SFTP::Constants::LockTypes
- Net::SFTP::Constants::OpenFlags
- Net::SFTP::Constants::OpenFlags::FV1
- Net::SFTP::Constants::OpenFlags::FV5
- Net::SFTP::Constants::OpenFlags::FV6
- Net::SFTP::Constants::PacketTypes
- Net::SFTP::Constants::RenameFlags
- Net::SFTP::Constants::StatusCodes
- Net::SFTP::Exception
- Net::SFTP::Operations
- Net::SFTP::Operations::Dir
- Net::SFTP::Operations::Download
- Net::SFTP::Operations::File
- Net::SFTP::Operations::FileFactory
- Net::SFTP::Operations::Upload
- Net::SFTP::Packet
- Net::SFTP::Protocol
- Net::SFTP::Protocol::Base
- Net::SFTP::Protocol::V01
- Net::SFTP::Protocol::V01::Attributes
- Net::SFTP::Protocol::V01::Base
- Net::SFTP::Protocol::V01::Name
- Net::SFTP::Protocol::V02
- Net::SFTP::Protocol::V02::Base
- Net::SFTP::Protocol::V03
- Net::SFTP::Protocol::V03::Base
- Net::SFTP::Protocol::V04
- Net::SFTP::Protocol::V04::Attributes
- Net::SFTP::Protocol::V04::Base
- Net::SFTP::Protocol::V04::Name
- Net::SFTP::Protocol::V05
- Net::SFTP::Protocol::V05::Base
- Net::SFTP::Protocol::V06
- Net::SFTP::Protocol::V06::Attributes
- Net::SFTP::Protocol::V06::Base
- Net::SFTP::Request
- Net::SFTP::Response
- Net::SFTP::Session
- Net::SFTP::StatusException
- Net::SFTP::Version
- Net::SSH
- Net::SSH::Connection
- Net::SSH::Connection::Session

No matching classes.

# Net::SFTP

Net::SFTP is a pure-Ruby module for programmatically interacting with a remote host via the SFTP protocol (that's SFTP as in "Secure File Transfer Protocol" produced by the Secure Shell Working Group, not "Secure FTP" and certainly not "Simple FTP").

See Net::SFTP#start for an introduction to the library. Also, see Net::SFTP::Session for further documentation.

### Public Class Methods

start(host, user, options={}, &block) click to toggle source

A convenience method for starting a standalone SFTP session. It will start up an SSH session using the given arguments (see the documentation for Net::SSH::Session for details), and will then start a new SFTP session with the SSH session. This will block until the new SFTP is fully open and initialized before returning it.

    sftp = Net::SFTP.start("localhost", "user")
    sftp.upload! "/local/file.tgz", "/remote/file.tgz"

If a block is given, it will be passed to the SFTP session and will be called once the SFTP session is fully open and initialized. When the block terminates, the new SSH session will automatically be closed.

    Net::SFTP.start("localhost", "user") do |sftp|
      sftp.upload! "/local/file.tgz", "/remote/file.tgz"
    end

    # File lib/net/sftp.rb, line 30
    def self.start(host, user, options={}, &block)
      session = Net::SSH.start(host, user, options)
      sftp = Net::SFTP::Session.new(session, &block).connect!

      if block_given?
        sftp.loop
        session.close
        return nil
      end

      sftp
    rescue Object => anything
      begin
        session.shutdown!
      rescue ::Exception
        # swallow exceptions that occur while trying to shutdown
      end

      raise anything
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.