diff --git a/app/services/sftp/directory.rb b/app/services/sftp/directory.rb index 15dbc34f..8501d316 100644 --- a/app/services/sftp/directory.rb +++ b/app/services/sftp/directory.rb @@ -6,7 +6,7 @@ module Sftp def self.open(path: '/data/survey_responses/clean', &block) sftp_url = ENV['SFTP_URL'] uri = URI.parse(sftp_url) - Net::SFTP.start(uri.host, uri.user, password: uri.password) do |sftp| + Net::SFTP.start(uri.host, uri.user, password: uri.password, keepalive: true, keepalive_interval: 5) do |sftp| sftp.dir.foreach(path) do |entry| next unless entry.file? diff --git a/app/services/sftp/file.rb b/app/services/sftp/file.rb index 7ad4ced6..25761410 100644 --- a/app/services/sftp/file.rb +++ b/app/services/sftp/file.rb @@ -6,7 +6,7 @@ module Sftp 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| + 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