mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 21:48:16 -08:00
27 lines
657 B
Ruby
27 lines
657 B
Ruby
require 'net/sftp'
|
|
require 'uri'
|
|
require 'csv'
|
|
|
|
module Sftp
|
|
class Directory
|
|
def self.open(path: '/data/survey_responses/clean', &block)
|
|
sftptogo_url = ENV['SFTPTOGO_URL']
|
|
uri = URI.parse(sftptogo_url)
|
|
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
|
|
sftp.dir.foreach(path) do |entry|
|
|
filename = entry.name
|
|
puts filename
|
|
|
|
sftp.file.open(filepath(path:, filename:), 'r', &block)
|
|
end
|
|
end
|
|
end
|
|
|
|
def self.filepath(path:, filename:)
|
|
path += '/' unless path.end_with?('/')
|
|
"#{path}#{filename}"
|
|
end
|
|
|
|
private_class_method :filepath
|
|
end
|
|
end
|