Ruby 또는 내가 한 일에 문제가있는 것 같은 매우 비정상적인 행동으로 보이는 문제가 있습니까? 제발 도와주세요 -이 문제를 해결하기 전까지 프로젝트가 지연되었습니다.간단한 Ruby SFTP 예제 구문 오류
맥 OS 레오파드에서 실행되는 코드 감안할 때 :
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)
예. url.user는 nil이었습니다. 왜냐하면 "sftp :: //[email protected]"형식을 사용하는 것을 잊었 기 때문입니다. RUBYOPT 문제, 즉 내부 문제에 대한 주장을 정리하는 데는 시간이 걸렸습니다. – Justicle
그래서 ... 대답은 그때 였나요? :) –
확실히 내 문제는 내 변수를 새로운 형식으로 업데이트하지 않은 경우 nil 인 값을 전달하여 발생합니다. @ip은 @ host.name이어야합니다. –