ruby-on-rails - ruby sftp 错误

标签 ruby-on-rails ruby scripting sftp

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

相关文章:

sql - Rails 包含条件不从左表返回所有结果的查询

html - 我的 Rails 应用程序的不同应用程序布局

ruby : the while loop does not work

shell - 从与 Applescript 相同的文件夹中运行 PKG 文件

linux - 如何删除除最后 2 个目录以及指向这些目录的符号链接(symbolic link)之外的所有目录

ruby - Selenium::WebDriver::Error::UnknownError:未知错误:找不到 Chrome 二进制文件(驱动程序信息:chromedriver=2.31.488774)

ruby-on-rails - ARel 中的绝对值( rails )

ruby-on-rails - 如何运行同一 Rails 应用程序的两个不同版本

ruby - 使用 OpenSSL 进行数字签名验证

Ruby - 按小时/天操作时间/日期时间?