我有一个看起来很不稳定的问题,这是 Ruby 的问题还是我做过的事情?请帮忙 - 我的项目在我解决这个问题之前一直停滞不前。
鉴于此代码在 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
仅供参考,我已正确设置 RUBYOPT,以便加载宝石并且我的宝石是最新的,根据:
$gem list --local
net-sftp (2.0.2, 1.1.0)
net-ssh (2.0.15, 1.1.2)