Class Net::SSH::Transport::VersionNegotiator
In: lib/net/ssh/transport/version-negotiator.rb
Parent: Object

Manages the negotiation of the version strings between client and server.

Methods

negotiate   new  

Constants

VERSION_LINE = /^SSH-/   For processing the version header. The version reported by the server must match this pattern.
REQUIRED_VERSION_PATTERN = /^SSH-(1.99|2.0)-/   Only versions matching this pattern are supported by Net::SSH.

Attributes

header_lines  [R]  An array of lines returned by the server prior to reporting the version.

Public Class methods

Creates a new VersionNegotiator object that logs to the given logger instance.

[Source]

    # File lib/net/ssh/transport/version-negotiator.rb, line 40
40:         def initialize( logger )
41:           @logger = logger
42:         end

Public Instance methods

Negotiate version information over the given socket. This will return the version reported by the server.

[Source]

    # File lib/net/ssh/transport/version-negotiator.rb, line 46
46:         def negotiate( socket, version )
47:           server_version = ""
48:           @header_lines = []
49: 
50:           loop do
51:             server_version = socket.readline
52:             break if server_version.nil? || VERSION_LINE.match( server_version )
53:             @header_lines << server_version
54:           end
55: 
56:           if !REQUIRED_VERSION_PATTERN.match( server_version )
57:             raise Net::SSH::Exception,
58:               "incompatible ssh version #{server_version.inspect}"
59:           end
60: 
61:           if @logger.debug?
62:             @logger.debug "remote server is #{server_version.chomp.inspect}"
63:           end
64:           socket.print "#{version}\r\n"
65: 
66:           return server_version.chomp
67:         end

[Validate]