Sha256: 8bcb543b6577acf49761a7dbd9811bae2c2f068e78210a3605855812eda1645b

Contents?: true

Size: 935 Bytes

Versions: 4

Compression:

Stored size: 935 Bytes

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 && !@ssh.closed?)
          @ssh.close
        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
      end

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ztk-1.6.25 lib/ztk/ssh/core.rb
ztk-1.6.24 lib/ztk/ssh/core.rb
ztk-1.6.23 lib/ztk/ssh/core.rb
ztk-1.6.22 lib/ztk/ssh/core.rb