Class: Idnow::SftpClient
- Inherits:
-
Object
- Object
- Idnow::SftpClient
- Defined in:
- lib/idnow/sftp_client.rb
Instance Method Summary collapse
- #download(file_name) ⇒ Object
-
#initialize(host:, username:, password:, options: {}) ⇒ SftpClient
constructor
A new instance of SftpClient.
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 = 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.merge(password: @password) Net::SFTP.start(@host, @username, ) 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 |