The simplest way to open a channel is via the @open_channel@ method of Net::SSH::Session.  By default, the channel will be of type "session", but you can optionally specify the channel type and any extra data to initialize the channel with. You also pass a block to the @open_channel@ invocation. This block will be called after the server has confirmed that the channel is valid and has been opened successfully.

The @open_channel@ method always returns immediately--all it does is inform the server that a channel needs to be opened and then registers the associated block as the callback to be invoked when the channel is confirmed.

This behavior is typical of most of the methods in the Net::SSH API; they simply send a request to the server and then (optionally) register a callback. Very few of them actually block (pause) until the server responds.

Here is an example of opening a channel:

{{{lang=ruby,caption=Opening a channel,number=true
Net::SSH.start( 'host' ) do |session|
  session.open_channel do |channel|
    puts "channel successfully opened... closing..."
    channel.close
  end

  session.loop
end
}}}

Note the use of the @close@ method for the channel. Just like most methods in the Net::SSH API, it does not immediately close the channel, but instead sends a close request to the server and returns. When the server responds that the channel has been closed, the framework will then call any final callbacks for the channel and then remove it.
