Class: EventMachine::Ssh

Inherits:
Object
  • Object
show all
Defined in:
lib/em-ssh.rb,
lib/em-ssh/log.rb,
lib/em-ssh/shell.rb,
lib/em-ssh/session.rb,
lib/em-ssh/version.rb,
lib/em-ssh/callbacks.rb,
lib/em-ssh/connection.rb,
lib/em-ssh/packet-stream.rb,
lib/em-ssh/server-version.rb,
lib/em-ssh/authentication-session.rb,
lib/em-ssh/connection/channel/interactive.rb,
lib/em-ssh/connection/channel/null-logger.rb

Overview

end

Examples:

EM::Ssh.start(host, user, :password => password) do |ssh|
 ssh.exec("hostname") do |ch,stream,data|
   puts "data: #{data}"
 end

Defined Under Namespace

Modules: Callbacks, Error, Log Classes: AuthenticationSession, ChannelOpenFailed, ClosedChannel, Connection, ConnectionFailed, ConnectionTerminated, ConnectionTimeout, Disconnect, Disconnected, NegotiationTimeout, PacketStream, ServerVersion, Session, Shell, SshError, TimeoutError

Constant Summary collapse

DEFAULT_PORT =
22
VERSION =
'0.7.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.logger(level = Logger::WARN) ⇒ Logger

Creates a logger when necessary

Returns:

  • (Logger)


98
99
100
# File 'lib/em-ssh.rb', line 98

def logger(level = Logger::WARN)
  @logger ||= ::Logger.new(STDERR).tap{ |l| l.level = level }
end

Class Method Details

.connect(host, user, opts = {}) {|Session| ... } ⇒ Session Also known as: start

Connect to an ssh server

Examples:

EM::Ssh.start(host, user, options) do |connection|
 log.debug "**** connected: #{connection}"
 connection.open_channel do |channel|
   log.debug "**** channel: #{channel}"
   channel.request_pty(options[:pty] || {}) do |pty,suc|

Parameters:

  • host (String)
  • user (String)
  • opts (Hash) (defaults to: {})

    all options accepted by Net::SSH.start

Yields:

  • (Session)

    an EventMachine compatible Net::SSH::Session

Returns:

See Also:



115
116
117
118
119
# File 'lib/em-ssh.rb', line 115

def connect(host, user, opts = {}, &blk)
  opts[:logger] || logger.debug("#{self}.connect(#{host}, #{user}, #{opts})")
  options = { :host => host, :user => user, :port => DEFAULT_PORT }.merge(opts)
  EM.connect(options[:host], options[:port], Connection, options, &blk)
end