Class: Kitchen::Transport::Sftp::Connection
- Inherits:
-
Ssh::Connection
- Object
- Ssh::Connection
- Kitchen::Transport::Sftp::Connection
- Defined in:
- lib/kitchen/transport/sftp.rb
Instance Method Summary collapse
-
#close ⇒ Object
Wrap Ssh::Connection#close to also shut down the SFTP connection.
-
#initialize(config, options, &block) ⇒ Connection
constructor
A new instance of Connection.
- #upload(locals, remote) ⇒ Object
Constructor Details
#initialize(config, options, &block) ⇒ Connection
Returns a new instance of Connection.
61 62 63 64 |
# File 'lib/kitchen/transport/sftp.rb', line 61 def initialize(config, , &block) @config = config super(, &block) end |
Instance Method Details
#close ⇒ Object
Wrap Ssh::Connection#close to also shut down the SFTP connection.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/kitchen/transport/sftp.rb', line 67 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
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/kitchen/transport/sftp.rb', line 92 def upload(locals, remote) Array(locals).each do |local| full_remote = File.join(remote, File.basename(local)) = { recursive: File.directory?(local), purge: File.basename(local) != 'cache', } recursive = File.directory?(local) time = Benchmark.realtime do sftp_upload!(local, full_remote, ) end logger.info("[SFTP] Time taken to upload #{local} to #{self}:#{full_remote}: %.2f sec" % time) end end |