You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/services/sftp/file.rb

18 lines
410 B

require 'net/sftp'
require 'uri'
module Sftp
class File
def self.open(filepath:, &block)
sftp_url = ENV['SFTP_URL']
uri = URI.parse(sftp_url)
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
sftp.file.open(filepath, 'r', &block)
end
rescue Net::SFTP::StatusException => e
puts "Error opening file: #{e.message}"
nil
end
end
end