Sha256: e737f1a36297bad505f1b38b7e1f6a17b9d4f10537ee07c35313d328ce044fe9

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

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:

[!figure 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.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
net-ssh-1.0.0 doc/manual/parts/channels_open.txt
net-ssh-0.9.0 doc/manual/parts/channels_open.txt