Ruby SFTP错误

9
我正在尝试使用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)

有什么想法我做错了吗?
2个回答

19

我相信在使用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


1

看起来上传目录会先尝试创建目标目录。

如果目标目录已经存在,则像原始示例中所示,mkdir 将失败。我仍在寻找一种使用内置的上传目录的方法 - 与此同时,我的程序遍历本地目录,并逐个上传每个文件。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接