Class: IOStreams::SFTP::Reader
- Inherits:
-
Object
- Object
- IOStreams::SFTP::Reader
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/io_streams/sftp/reader.rb
Class Method Summary collapse
-
.open(file_name, user:, password:, host:, port: 22, binary: true, options: {}, &block) ⇒ Object
Stream to a remote file over sftp.
Class Method Details
.open(file_name, user:, password:, host:, port: 22, binary: true, options: {}, &block) ⇒ Object
Stream to a remote file over sftp.
file_name: [String]
Name of file to read from.
user: [String]
Name of user to login with.
password: [String]
Password for the user.
host: [String]
Name of the host to connect to.
port: [Integer]
Port to connect to at the above host.
binary [true|false]
Whether to write in binary mode
Default: true
options: [Hash]
Any supported by Net::SSH.start
Note:
-
Net::SFTP::StatusException means the file could not be read
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/io_streams/sftp/reader.rb', line 41 def self.open(file_name, user:, password:, host:, port: 22, binary: true, options: {}, &block) raise(NotImplementedError, 'Can only SFTP directly to a file name, not another stream.') if IOStreams.writer_stream?(file_name) begin require 'net/sftp' unless defined?(Net::SFTP) rescue LoadError => e raise(LoadError, "Please install the 'net-sftp' gem for SFTP streaming support. #{e.}") end = .dup [:logger] ||= self.logger if defined?(SemanticLogger) [:port] ||= 22 [:max_pkt_size] ||= 65536 [:password] = password [:port] = port mode = binary ? 'rb' : 'r' result = nil Net::SFTP.start(host, user, ) do |sftp| result = sftp.file.open(file_name, mode, &block) end result end |