Class: Anyfetch::SFTP
- Inherits:
-
Object
- Object
- Anyfetch::SFTP
- Defined in:
- lib/anyfetch/sftp.rb
Instance Method Summary collapse
-
#initialize(uri, options = {}) ⇒ SFTP
constructor
A new instance of SFTP.
- #open ⇒ Object
Constructor Details
#initialize(uri, options = {}) ⇒ SFTP
Returns a new instance of SFTP.
5 6 7 8 |
# File 'lib/anyfetch/sftp.rb', line 5 def initialize(uri, = {}) @uri = uri @options = end |
Instance Method Details
#open ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/anyfetch/sftp.rb', line 10 def open user = @options.delete(:user) || @uri.user = { password: @uri.password }.merge(@options) filename = ::File.basename(@uri.path) tempfile = Tempfile.new(filename) tempfile.binmode Net::SFTP.start(@uri.host, user, ) do |sftp| sftp.file.open(@uri.path, "r") do |file| while !file.eof? do tempfile << file.read(32 * 1024 * 1024) end end end tempfile.extend(OriginalFilename::Path) end |