Sha256: 2622f1be3f52100dbe7a5116e194e973a60585497d6edce7a58f1c67beaeb7c9

Contents?: true

Size: 1.44 KB

Versions: 15

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:

{{{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

15 entries across 15 versions & 1 rubygems

Version Path
net-ssh-1.0.1 doc/manual/parts/0013.txt
net-ssh-1.0.10 doc/manual/parts/0013.txt
net-ssh-1.0.2 doc/manual/parts/0013.txt
net-ssh-1.0.8 doc/manual/parts/0013.txt
net-ssh-1.0.3 doc/manual/parts/0013.txt
net-ssh-1.0.9 doc/manual/parts/0013.txt
net-ssh-1.0.4 doc/manual/parts/0013.txt
net-ssh-1.0.6 doc/manual/parts/0013.txt
net-ssh-1.0.7 doc/manual/parts/0013.txt
net-ssh-1.0.5 doc/manual/parts/0013.txt
net-ssh-1.1.0 doc/manual/parts/0013.txt
net-ssh-1.1.1 doc/manual/parts/0013.txt
net-ssh-1.1.2 doc/manual/parts/0013.txt
net-ssh-1.1.4 doc/manual/parts/0013.txt
net-ssh-1.1.3 doc/manual/parts/0013.txt