非常に不安定な動作のように見える問題がありますが、これはRubyの問題ですか、それとも私が行ったことの問題ですか?助けてください-私がこれを解決するまで私のプロジェクトは行き詰まっています。
このコードがMacOSLeopardで実行されているとすると、次のようになります。
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が読み込まれ、gemが最新になります。
$gem list --local
net-sftp (2.0.2, 1.1.0)
net-ssh (2.0.15, 1.1.2)