class Anyfetch::SFTP

Public Class Methods

new(uri, options = {}) click to toggle source
# File lib/anyfetch/sftp.rb, line 5
def initialize(uri, options = {})
  @uri = uri
  @options = options
end

Public Instance Methods

open() click to toggle source
# File lib/anyfetch/sftp.rb, line 10
def open
  user = @options.delete(:user) || @uri.user
  options = { password: @uri.password }.merge(@options)

  filename = ::File.basename(@uri.path)

  tempfile = Tempfile.new(filename)
  tempfile.binmode

  Net::SFTP.start(@uri.host, user, options) 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