lib/io_streams/paths/sftp.rb
def sftp_download(remote_file_name, local_file_name)
        with_sftp_args do |args|
          Open3.popen2e(*args) do |writer, reader, waith_thr|
            # Give time for remote sftp server to get ready to accept the password.
            sleep self.class.before_password_wait_seconds

            writer.puts password

            # Give time for password to be processed and stdin to be passed to sftp process.
            sleep self.class.sshpass_wait_seconds

            writer.puts "get #{remote_file_name} #{local_file_name}"
            writer.puts "bye"
            writer.close
            out = reader.read.chomp
            unless waith_thr.value.success?
              raise(
                Errors::CommunicationsFailure,
                "Download failed calling #{self.class.sftp_bin} via #{self.class.sshpass_bin}: #{out}"
              )
            end

            out
          rescue Errno::EPIPE
            out = begin
              reader.read.chomp
            rescue StandardError
              nil
            end
            raise(
              Errors::CommunicationsFailure,
              "Download failed calling #{self.class.sftp_bin} via #{self.class.sshpass_bin}: #{out}"
            )
          end
        end
      end
# Use sftp and sshpass executables to download to a local file
Use sftp and sshpass executables to download to a local file
Use sftp and sshpass executables to download to a local file
def sftp_download(remote_file_name, local_file_name)
        with_sftp_args do |args|
          Open3.popen2e(*args) do |writer, reader, waith_thr|
            sleep self.class.before_password_wait_seconds
            writer.puts password
            sleep self.class.sshpass_wait_seconds
            writer.puts "get #{remote_file_name} #{local_file_name}"
            writer.puts "bye"
            writer.close
            out = reader.read.chomp
            unless waith_thr.value.success?
              raise(
                Errors::CommunicationsFailure,
                "Download failed calling #{self.class.sftp_bin} via #{self.class.sshpass_bin}: #{out}"
              )
            end
            out
          rescue Errno::EPIPE
            out = begin
              reader.read.chomp
            rescue StandardError
              nil
            end
            raise(
              Errors::CommunicationsFailure,
              "Download failed calling #{self.class.sftp_bin} via #{self.class.sshpass_bin}: #{out}"
            )
          end
        end
      end
def sftp_download ( remote_file_name , local_file_name ) with_sftp_args do | args | Open3 . popen2e ( * args ) do | writer , reader , waith_thr | sleep self . class . before_password_wait_seconds writer . puts password sleep self . class . sshpass_wait_seconds writer . puts "get #{remote_file_name} #{local_file_name}" writer . puts "bye" writer . close out = reader . read . chomp unless waith_thr . value . success? raise ( Errors :: CommunicationsFailure , "Download failed calling #{self.class.sftp_bin} via #{self.class.sshpass_bin}: #{out}" ) end out rescue Errno :: EPIPE out = begin reader . read . chomp rescue StandardError nil end raise ( Errors :: CommunicationsFailure , "Download failed calling #{self.class.sftp_bin} via #{self.class.sshpass_bin}: #{out}" ) end end end
Use sftp and sshpass executables to download to a local file
Use sftp and sshpass executables to download to a local file
# Give time for remote sftp server to get ready to accept the password. # Give time for password to be processed and stdin to be passed to sftp process.
remote_file_name
local_file_name