Class: Net::SFTP::Operations::FileFactory

### Home Classes Methods

### In Files

- lib/net/sftp/operations/file_factory.rb

### Parent

Object

### Methods

- ::new
- #directory?
- #open

### 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::Operations::FileFactory

A factory class for opening files and returning Operations::File instances that wrap the SFTP handles that represent them. This is a convenience class for use when working with files synchronously. Rather than relying on the programmer to provide callbacks that define a state machine that describes the behavior of the program, this class (and Operations::File) provide an interface where calls will block until they return, mimicking the IO class' interface.

### Attributes

sftp[R]

The SFTP session object that drives this file factory.

### Public Class Methods

new(sftp) click to toggle source

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

    # File lib/net/sftp/operations/file_factory.rb, line 18
    def initialize(sftp)
      @sftp = sftp
    end

### Public Instance Methods

directory?(path) click to toggle source

Returns `true` if the argument refers to a directory on the remote host.

    # File lib/net/sftp/operations/file_factory.rb, line 55
    def directory?(path)
      sftp.lstat!(path).directory?
    end

open(name, flags="r", mode=nil) → file click to toggle source
open(name, flags="r", mode=nil) { |file| ... }

Attempt to open a file on the remote server. The `flags` parameter accepts the same values as the standard Ruby ::File#open method. The `mode` parameter must be an integer describing the permissions to use if a new file is being created.

If a block is given, the new Operations::File instance will be yielded to it, and closed automatically when the block terminates. Otherwise the object will be returned, and it is the caller's responsibility to close the file.

    sftp.file.open("/tmp/names.txt", "w") do |f|
      # ...
    end

    # File lib/net/sftp/operations/file_factory.rb, line 39
    def open(name, flags="r", mode=nil, &block)
      handle = sftp.open!(name, flags, :permissions => mode)
      file = Operations::File.new(sftp, handle)

      if block_given?
        begin
          yield file
        ensure
          file.close
        end
      else
        return file
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.