Class: IOP::SFTPFileReader
- Inherits:
-
RandomAccessReader
- Object
- RandomAccessReader
- IOP::SFTPFileReader
- Includes:
- Feed
- Defined in:
- lib/iop/net/sftp.rb
Overview
Note:
this class depends on external +net-sftp+ gem.
Feed class to read file from SFTP server.
This class an adapter for +Net::SFTP::Session+ class.
Use case: retrieve current user's ~/.profile file from SFTP server running on local machine and and compute its MD5 hash sum.
require 'iop/digest'
require 'iop/net/sftp'
( IOP::SFTPFileReader.new('localhost', '.profile') | (d = IOP::DigestComputer.new(Digest::MD5.new)) ).process!
puts d.digest.hexdigest
Instance Attribute Summary
Attributes included from Feed
Instance Method Summary collapse
-
#initialize(sftp, file, size: nil, offset: nil, block_size: DEFAULT_BLOCK_SIZE, **options) ⇒ SFTPFileReader
constructor
Creates class instance.
- #process! ⇒ Object
Methods included from Feed
Methods inherited from RandomAccessReader
Constructor Details
#initialize(sftp, file, size: nil, offset: nil, block_size: DEFAULT_BLOCK_SIZE, **options) ⇒ SFTPFileReader
Creates class instance.
sftp can be either a +String+ of +Net::SFTP::Session+ instance. If it is a string a corresponding +Net::SFTP::Session+ instance will be created with options passed to its constructor.
If sftp is a string, a created SFTP session is managed, e.g. it is closed after the process is complete, otherwise supplied object is left as is and no closing is performed. This allows to reuse SFTP session for a sequence of operations.
Refer to +Net::SFTP+ documentation for available options.
73 74 75 76 77 78 |
# File 'lib/iop/net/sftp.rb', line 73 def initialize(sftp, file, size: nil, offset: nil, block_size: DEFAULT_BLOCK_SIZE, **) super(size: size, offset: offset, block_size: block_size) = @file = file @sftp = sftp end |
Instance Method Details
#process! ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/iop/net/sftp.rb', line 80 def process! setup begin @io = @sftp.open!(@file, 'r') begin super ensure @sftp.close(@io) end ensure cleanup end end |