Class: Idnow::SftpClient

Inherits:
Object
  • Object
show all
Defined in:
lib/idnow/sftp_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(host:, username:, password:, options: {}) ⇒ SftpClient

Returns a new instance of SftpClient.



7
8
9
10
11
12
# File 'lib/idnow/sftp_client.rb', line 7

def initialize(host:, username:, password:, options: {})
  @host = URI.parse(host).host
  @username = username
  @password = password
  @options = options
end

Instance Method Details

#download(file_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/idnow/sftp_client.rb', line 14

def download(file_name)
  data = nil
  options = @options.merge(password: @password)
  Net::SFTP.start(@host, @username, options) do |sftp|
    raise Idnow::Exception, "Invalid path. No identification file found under #{file_name}" unless file_exists(sftp, file_name)

    begin
      data = sftp.download!(file_name)
    rescue Net::SFTP::Exception => e
      raise Idnow::ConnectionException, e
    end
  end
  data
end