Method: Net::SSH::Connection::Channel#send_channel_request

Defined in:
lib/net/ssh/connection/channel.rb

#send_channel_request(request_name, *data, &callback) ⇒ Object

Sends a new channel request with the given name. The extra data parameter must either be empty, or consist of an even number of arguments. See Net::SSH::Buffer.from for a description of their format. If a block is given, it is registered as a callback for a pending request, and the packet will be flagged so that the server knows a reply is required. If no block is given, the server will send no response to this request. Responses, where required, will cause the callback to be invoked with the channel as the first argument, and either true or false as the second, depending on whether the request succeeded or not. The meaning of “success” and “failure” in this context is dependent on the specific request that was sent.

channel.send_channel_request "shell" do |ch, success|
  if success
    puts "user shell started successfully"
  else
    puts "could not start user shell"
  end
end

Most channel requests you’ll want to send are already wrapped in more convenient helper methods (see #exec and #subsystem).



488
489
490
491
492
493
494
495
496
497
# File 'lib/net/ssh/connection/channel.rb', line 488

def send_channel_request(request_name, *data, &callback)
  info { "sending channel request #{request_name.inspect}" }
  fail "Channel open not yet confirmed, please call send_channel_request(or exec) from block of open_channel" unless remote_id

  msg = Buffer.from(:byte, CHANNEL_REQUEST,
                    :long, remote_id, :string, request_name,
                    :bool, !callback.nil?, *data)
  connection.send_message(msg)
  pending_requests << callback if callback
end