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.
18 lines
450 B
18 lines
450 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, keepalive: true, keepalive_interval: 5) do |sftp|
|
|
sftp.file.open(filepath, 'r', &block)
|
|
end
|
|
rescue Net::SFTP::StatusException => e
|
|
puts "Error opening file: #{e.message}"
|
|
nil
|
|
end
|
|
end
|
|
end
|