2015-02-09 68 views
0

我想通過紅寶石控制檯連接到sftp服務器。Net :: SFTP無法通過Ruby控制檯連接

代碼片斷:::

Net::SFTP.start(IP, USERNAME, password: PASS) do |sftp| 
..... 
end 

它引發以下錯誤::::

Net::SSH::Disconnect: disconnected: No Host (7) 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:188:in `block in poll_message' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `loop' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `poll_message' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:163:in `next_message' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:95:in `block in next_message' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:94:in `loop' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:94:in `next_message' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/methods/none.rb:14:in `authenticate' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:79:in `block in authenticate' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:66:in `each' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:66:in `authenticate' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-ssh-2.9.2/lib/net/ssh.rb:211:in `start' 
    from /Users/venkatesan/.rvm/gems/[email protected]/gems/net-sftp-2.1.2/lib/net/sftp.rb:31:in `start' 
    from (irb):143 
    from /Users/venkatesan/.rvm/rubies/ruby-1.9.3-p385/bin/irb:16:in `<main>' 

我使用的Net :: SSH以及..得到了同樣的錯誤嘗試。

但是當我做sftp USERNAME然後它提示輸入密碼。當我在終端輸入密碼時,它連接正確。但不能通過ruby代碼單獨連接。

有人可以拋出一些光嗎?

+0

這是什麼意思「當我做sftp USERNAME」?你的意思是命令行'sftp'客戶端?你如何在命令行上指定主機/ IP?如果你只是'sftp USERNAME',你就連接到本地主機。 – 2015-02-09 07:16:03

+0

Martin, 所以我在終端上做的是 sftp 它要求輸入密碼,並連接上。 如果我在紅寶石代碼中使用相同的HOST和密碼,它說「Net :: SSH :: Disconnect:disconnected:No Host(7)」 你能幫忙嗎? – Venky 2015-02-24 02:08:19

回答

0

終於找到原因..我給了錯誤的參數。它是user @ host。我的參數不正確。

Thanks guys guys