lib/io_streams/paths/sftp.rb in iostreams-1.6.1 vs lib/io_streams/paths/sftp.rb in iostreams-1.6.2
- old
+ new
@@ -24,16 +24,17 @@
# end
class SFTP < IOStreams::Path
include SemanticLogger::Loggable if defined?(SemanticLogger)
class << self
- attr_accessor :sshpass_bin, :sftp_bin, :sshpass_wait_seconds
+ attr_accessor :sshpass_bin, :sftp_bin, :sshpass_wait_seconds, :before_password_wait_seconds
end
- @sftp_bin = "sftp"
- @sshpass_bin = "sshpass"
- @sshpass_wait_seconds = 5
+ @sftp_bin = "sftp"
+ @sshpass_bin = "sshpass"
+ @before_password_wait_seconds = 2
+ @sshpass_wait_seconds = 5
attr_reader :hostname, :username, :ssh_options, :url, :port
# Stream to a remote file over sftp.
#
@@ -166,13 +167,18 @@
# 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|
begin
+ # 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?
@@ -269,12 +275,12 @@
args << "#{username}@#{hostname}"
args
end
def build_ssh_options
- options = ssh_options.dup
- options[:logger] ||= logger if defined?(SemanticLogger)
- options[:port] ||= port
+ options = ssh_options.dup
+ options[:logger] ||= logger if defined?(SemanticLogger)
+ options[:port] ||= port
options[:max_pkt_size] ||= 65_536
options[:password] ||= @password
options
end