From aa39303dfc2e0bde959a780ccdef05db430a8af1 Mon Sep 17 00:00:00 2001 From: rebuilt Date: Thu, 18 Sep 2025 08:05:25 -0700 Subject: [PATCH] fix: keep alive long running sftp connections --- app/services/sftp/directory.rb | 2 +- app/services/sftp/file.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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