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.
24 lines
1.1 KiB
24 lines
1.1 KiB
namespace :upload do
|
|
desc 'upload cleaned Lowell CSVs to the SFTP server'
|
|
task lowell: :environment do
|
|
new_files = Array.new
|
|
input_filepath = Rails.root.join('tmp', 'data', 'rpp_data', 'clean')
|
|
Dir.foreach(input_filepath) do |filename|
|
|
next if filename.start_with?('.') # skip hidden files and ./.. directories
|
|
# this can probably be replaced with Dir.join or similar
|
|
input_filename = Rails.root.join('tmp', 'data', 'rpp_data', 'clean', filename).to_s
|
|
sftptogo_url = ENV['SFTPTOGO_URL']
|
|
uri = URI.parse(sftptogo_url)
|
|
Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp|
|
|
puts "Uploading #{filename}..."
|
|
sftp.upload!(input_filename, "/data/survey_responses/clean/#{filename}")
|
|
end
|
|
new_files.append(filename)
|
|
end
|
|
# print remote directory contents with new files marked
|
|
path = '/data/survey_responses/clean/'
|
|
Sftp::Directory.open(path:) do |file|
|
|
# the open method already prints all the contents...
|
|
end
|
|
end
|
|
end |