ssh: how to send data request after send_data?
After openning a ssh session to the remote host and queued some data through send_data, how to really trigger the action to s开发者_JS百科end out the data to the remote host? chan.send_request does not work in V2.0(e.g: chan.send_request "shell", nil, true ). A simple example will be very helpful!
Net::SSH.start('remotehost','user') do |session|
session.open_channel do |chan|
chan.send_data "..."
chan.send_data "..."
???
Thanks a lot! Dan
You need to initiate a shell, try something like:
chan.request_pty do |ch, success|
raise "Error requesting pty" unless success
ch.send_channel_request("shell") do |ch, success|
raise "Error opening shell" unless success
end
end
If you want to see the output of your commands you need to register a handler:
chan.on_data do |ch, data|
# work with output here
end
(or for standard error output use chan.on_extended_data
)
精彩评论