【问题标题】:ruby shoes ssh connection红宝石鞋ssh连接
【发布时间】:2011-09-11 20:47:56
【问题描述】:

我正在试鞋,但卡住了。我正在尝试使用 ssh 连接到远程计算机并发出命令,让它在 cli 中工作,但我不能让它在鞋子上工作。 这可能是一件简单的事情,但我是新事物,我无法克服它。 这是我的代码在 atm 的样子

Shoes.setup do
gem 'net-ssh'

end
require "rubygems"
require "net/ssh"
Shoes.app do
  button "Connect" do
  append Net::SSH.start( '192.168.100.127', 'fox', :password => "xxxxxx" ) do 
  |ssh_connection|
  ssh_connection.open_channel do |channel|
        channel.on_data do |ch, data|
          puts data
          channel.exec "ls -la" do |ch, success|
            para success
          if success then
            alert "uploaded"
          else
            alert "Fail"
          end
        end
      end
  end
end
end
end

【问题讨论】:

  • 显示您的密码不是最好的主意 ;) 即使是本地服务
  • 我从帖子中删除了密码。
  • 请解释您遇到了什么错误。

标签: ruby shoes


【解决方案1】:

您的代码首先尝试接收数据,但通常情况并非如此。删除 on_data:

Shoes.app do
  button "Connect" do
    append Net::SSH.start( '192.168.100.127', 'fox', :password => "xxxxxx" ) do |ssh_connection|
      ssh_connection.open_channel do |channel|
        channel.exec "ls -la" do |ch, success|
          para success
          if success then
            alert "uploaded"
          else
            alert "Fail"
          end
        end
      end
    end
  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多