Sha256: 3c4bb6af712f25b44a758d59fec78cd441503727b0742d9f8360c25b5f00d187

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

module ZTK
  class SSH

    # SSH Core Functionality
    module Core

      # Starts an SSH session.  Can also be used to get the Net::SSH object.
      #
      # Primarily used internally.
      def ssh
        @ssh ||= Net::SSH.start(config.host_name, config.user, ssh_options)
        @ssh
      end

      # Starts an SFTP session.  Can also be used to get the Net::SFTP object.
      #
      # Primarily used internally.
      def sftp
        @sftp ||= self.ssh.sftp
        @sftp
      end

      # Close our session gracefully.
      def close
        config.ui.logger.debug { "close" }

        if (!@ssh.nil? && !@ssh.closed?)
          config.ui.logger.debug { "SSH object is valid and not closed" }

          begin
            config.ui.logger.debug { "attempting to close" }
            @ssh.close
            config.ui.logger.debug { "closed" }

          rescue Exception => e
            config.ui.logger.fatal { "EXCEPTION: #{e.inspect}" }
          end

        else
          config.ui.logger.debug { "SSH object is NIL!" }
        end

        @ssh = nil
        @sftp = nil

        true
      end

      # The on_retry method we'll use with the RescueRetry class.
      def on_retry(exception)
        config.ui.logger.warn { "ZTK::SSH on_retry triggered!" }

        (close rescue false)
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ztk-1.9.1 lib/ztk/ssh/core.rb
ztk-1.9.0 lib/ztk/ssh/core.rb
ztk-1.8.0 lib/ztk/ssh/core.rb
ztk-1.7.1 lib/ztk/ssh/core.rb
ztk-1.7.0 lib/ztk/ssh/core.rb
ztk-1.6.30 lib/ztk/ssh/core.rb