我有一個問題,似乎非常片狀行爲,這是Ruby的問題還是我已經做了什麼?請幫助 - 我的項目停滯不前,直到我解決這個問題。簡單的紅寶石SFTP示例語法錯誤
鑑於這種代碼在Mac OS Leopard的運行:
require 'uri'
require 'net/ssh'
require 'net/sftp'
include Net
def copy_from_uri(uri, local_path)
# SFTP copy
SFTP.start(uri.host, uri.user, :password => 'password') do |sftp|
puts "downloading from #{uri.host}, path #{uri.path}\n"
sftp.download(uri.path, local_path)
end
end
remote_uri = URI.parse("sftp://example.com/test.mp4")
local_file = "/tmp/remote_copy_test.mp4"
result = copy_from_uri(remote_uri, local_file);
什麼會導致下面的錯誤?
$ ruby sftp_fail.rb
/Library/Ruby/Site/1.8/net/sftp.rb:43:in `start': undefined method `shutdown!'
for nil:NilClass (NoMethodError)
from sftp_fail.rb:8:in `copy_from_uri'
from sftp_fail.rb:18
FYI我設置RUBYOPT正確左右的寶石被加載和我的寶石均達到最新的,按照:
$gem list --local
net-sftp (2.0.2, 1.1.0)
net-ssh (2.0.15, 1.1.2)
是的。 uri.user是零,因爲我忘記使用格式「sftp :: //[email protected]」。我花了一段時間才解決RUBYOPT問題,因此指責了一個內部問題。 – Justicle 2009-10-28 01:19:59
所以......這就是答案,不是嗎? :) – 2009-10-28 01:56:54
絕對是由於傳遞一個值爲零的問題,在我的情況下,我沒有更新我的變量到我的新格式@ip應該是@ host.name – 2009-11-07 07:55:26