Parent

Methods

Included Modules

Class Index [+]

Quicksearch

Net::SSH::Transport::ServerVersion

Negotiates the SSH protocol version and trades information about server and client. This is never used directly—it is always called by the transport layer as part of the initialization process of the transport layer.

Note that this class also encapsulates the negotiated version, and acts as the authoritative reference for any queries regarding the version in effect.

Constants

PROTO_VERSION

The SSH version string as reported by Net::SSH

Attributes

header[R]

Any header text sent by the server prior to sending the version.

version[R]

The version string reported by the server.

Public Class Methods

new(socket, logger) click to toggle source

Instantiates a new ServerVersion and immediately (and synchronously) negotiates the SSH protocol in effect, using the given socket.

    # File lib/net/ssh/transport/server_version.rb, line 28
28:     def initialize(socket, logger)
29:       @header = ""
30:       @version = nil
31:       @logger = logger
32:       negotiate!(socket)
33:     end

Private Instance Methods

negotiate!(socket) click to toggle source

Negotiates the SSH protocol to use, via the given socket. If the server reports an incompatible SSH version (e.g., SSH1), this will raise an exception.

    # File lib/net/ssh/transport/server_version.rb, line 40
40:       def negotiate!(socket)
41:         info { "negotiating protocol version" }
42: 
43:         loop do
44:           @version = ""
45:           loop do
46:             begin
47:               b = socket.readpartial(1)
48:               raise Net::SSH::Disconnect, "connection closed by remote host" if b.nil?
49:             rescue EOFError => e
50:               raise Net::SSH::Disconnect, "connection closed by remote host"
51:             end
52:             @version << b
53:             break if b == "\n"
54:           end
55:           break if @version.match(/^SSH-/)
56:           @header << @version
57:         end
58: 
59:         @version.chomp!
60:         debug { "remote is `#{@version}'" }
61: 
62:         unless @version.match(/^SSH-(1\.99|2\.0)-/)
63:           raise Net::SSH::Exception, "incompatible SSH version `#{@version}'"
64:         end
65: 
66:         debug { "local is `#{PROTO_VERSION}'" }
67:         socket.write "#{PROTO_VERSION}\r\n"
68:         socket.flush
69:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.