class SSHClient::Transport::NetSSH

Attributes

ssh[R]

Public Instance Methods

close() click to toggle source
# File lib/ssh_client/transport/net_ssh.rb, line 45
def close
  @ssh.close if !closed?
end
closed?() click to toggle source
# File lib/ssh_client/transport/net_ssh.rb, line 41
def closed?
  ssh.nil? || ssh.closed?
end
open() click to toggle source
# File lib/ssh_client/transport/net_ssh.rb, line 36
def open
  @ssh = Net::SSH.start config.hostname, config.username,
    password: config.password, logger: config.debug? && config.logger
end
send_message(command, close: false) click to toggle source
# File lib/ssh_client/transport/net_ssh.rb, line 9
def send_message(command, close: false)
  open if closed?
  last_read_time = nil

  ssh.open_channel do |channel|
    channel.send_channel_request 'shell' do |ch, success|
      channel.on_data do |c, data|
        handle_listeners :stdout, data
        last_read_time = Time.now
      end

      channel.on_extended_data do |c, data|
        handle_listeners :stderr, data
      end

      channel.send_data "#{command}\n"
    end
  end

  ssh.loop(0.1) do
    read_timeout = Time.now - last_read_time if last_read_time
    ssh.busy? && (!read_timeout || read_timeout < config.read_timeout)
  end

  ssh.close if close
end