diff --git a/Gemfile b/Gemfile index 1068bf73..5fe67a50 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,9 @@ gem 'stimulus-rails' gem 'watir' gem 'selenium-webdriver', '~> 4.4' +gem 'net-sftp' +gem 'ed25519' +gem 'bcrypt_pbkdf' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index d3b85ac9..e2221006 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -82,6 +82,7 @@ GEM ast (2.4.2) backport (1.2.0) bcrypt (3.1.18) + bcrypt_pbkdf (1.1.0) benchmark (0.2.1) better_html (2.0.1) actionview (>= 6.0) @@ -131,6 +132,7 @@ GEM diff-lcs (1.5.0) docile (1.4.0) e2mmap (0.1.0) + ed25519 (1.3.0) erb_lint (0.3.1) activesupport better_html (>= 2.0.1) @@ -207,8 +209,11 @@ GEM net-protocol net-protocol (0.2.1) timeout + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) net-smtp (0.3.3) net-protocol + net-ssh (7.0.1) newrelic_rpm (8.16.0) nio4r (2.5.8) nokogiri (1.14.2-x86_64-darwin) @@ -413,6 +418,7 @@ PLATFORMS DEPENDENCIES activerecord-import apparition! + bcrypt_pbkdf bootsnap brakeman bullet @@ -422,6 +428,7 @@ DEPENDENCIES database_cleaner debug devise + ed25519 erb_lint erblint-github factory_bot_rails @@ -433,6 +440,7 @@ DEPENDENCIES launchy listen (~> 3.0.5) nested_scaffold + net-sftp newrelic_rpm nokogiri (>= 1.13.4) omniauth diff --git a/app/services/sftp/downloader.rb b/app/services/sftp/downloader.rb new file mode 100644 index 00000000..c1bcd714 --- /dev/null +++ b/app/services/sftp/downloader.rb @@ -0,0 +1,26 @@ +require 'net/sftp' +require 'uri' +require 'csv' + +module Sftp + class Downloader + def initialize + sftptogo_url = ENV['SFTPTOGO_URL'] + uri = URI.parse(sftptogo_url) + Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp| + # download a file or directory from the remote host + # open and read from a pseudo-IO for a remote file + # sftp.file.open('/mciea/data/canary.csv', 'r') do |f| + # CSV.parse(f.read) do |row| + # puts row + # end + # end + + # list the entries in a directory + sftp.dir.foreach('/mciea/data/') do |entry| + puts entry.longname + end + end + end + end +end