我正在尝试使用 ruby 将文件上传到我的 sftp,我可以通过 ssh 登录,一切正常,但我的脚本失败了......这是我的小脚本
require 'rubygems'
require 'net/sftp'
Net::SFTP.start('50.5.54.77', 'root', :password => 'PASSWORD') do |sftp|
# upload a file or directory to the remote host
sftp.upload!("/Users/tamer/sites/sandbox/move_me.txt", "/home")
end
但我一直收到这个错误
ruby sftp.rb
/Library/Ruby/Gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/operations/upload.rb:313:in `on_open':
Net::SFTP::StatusException open /srv (4, "failure") (Net::SFTP::StatusException)
知道我做错了什么
最佳答案
我相信在使用 sftp 时,必须指定目标文件。
Net::SFTP.start('50.5.54.77', 'root', :password => 'PASSWORD') do |sftp|
# upload a file or directory to the remote host
sftp.upload!("/Users/tamer/sites/sandbox/move_me.txt", "/home/move_me.txt")
end
在文档中,示例使用文件的远程路径,而不仅仅是目录。
http://net-ssh.github.com/sftp/v2/api/classes/Net/SFTP/Operations/Upload.html
关于ruby-on-rails - ruby sftp 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7178895/