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:) ⇒ SftpClient

Returns a new instance of SftpClient.



5
6
7
8
9
# File 'lib/idnow/sftp_client.rb', line 5

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

Instance Method Details

#download(file_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/idnow/sftp_client.rb', line 11

def download(file_name)
  data = nil
  Net::SFTP.start(@host, @username, password: @password) do |sftp|
    fail Idnow::Exception, "Invalid path. No identification file found under #{file_name}" if sftp.dir['.', file_name].empty?
    begin
      data = sftp.download!(file_name)
    rescue Net::SFTP::Exception => e
      raise Idnow::ConnectionException, e
    end
  end
  data
end