Class: Kitchen::Transport::Sftp::Connection

Inherits:
Ssh::Connection
  • Object
show all
Defined in:
lib/kitchen/transport/sftp.rb

Instance Method Summary collapse

Instance Method Details

#closeObject

Wrap Ssh::Connection#close to also shut down the SFTP connection.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kitchen/transport/sftp.rb', line 50

def close
  if @sftp_session
    logger.debug("[SFTP] closing connection to #{self}")
    begin
      sftp_session.close_channel
    rescue Net::SSH::Disconnect
      # Welp, we tried.
    rescue IOError
      # Can happen with net-ssh 4.x, no idea why.
      # See https://github.com/net-ssh/net-ssh/pull/493
    end
  end
ensure
  @sftp_session = nil
  # Make sure we can turn down the session even if closing the channels
  # fails in the middle because of a remote disconnect.
  saved_session = @session
  begin
    super
  rescue Net::SSH::Disconnect
    # Boooo zlib warnings.
    saved_session.transport.close if saved_session
  end
end

#upload(locals, remote) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kitchen/transport/sftp.rb', line 75

def upload(locals, remote)
  Array(locals).each do |local|
    full_remote = File.join(remote, File.basename(local))
    options = {
      recursive: File.directory?(local),
      purge: File.basename(local) != 'cache',
    }
    recursive = File.directory?(local)
    time = Benchmark.realtime do
      sftp_upload!(local, full_remote, options)
    end
    logger.info("[SFTP] Time taken to upload #{local} to #{self}:#{full_remote}: %.2f sec" % time)
  end
end