简体   繁体   English

使用 Rails SFTP 上传文件时出现“权限被拒绝”

[英]"permission denied" when uploading a file with Rails SFTP

I am working on an integration that requires my Rails 4 app to push a CSV to an SFTP server daily.我正在开发一个需要我的 Rails 4 应用程序每天将 CSV 推送到 SFTP 服务器的集成。 The app will eventually live on Heroku.该应用程序最终将在 Heroku 上运行。

I am using the 'net-sftp' gem.我正在使用“net-sftp”gem。

Moving the file via FTP client (FileZilla) works.通过 FTP 客户端 (FileZilla) 移动文件有效。

Here's the very simple class I'm trying to use:这是我正在尝试使用的非常简单的类:

require 'net/ssh'
require 'net/sftp'

class SFTP

 def initialize(org)
    case org
    when 'client'
        @host = ENV['HOST']
        @username = ENV['USERNAME']
        @password = ENV['PASSWORD']
        @port = ENV['PORT']
    end
 end

 def send(local_path)
    Net::SFTP.start(@host, @username , { password: @password, port: @port } ) do |sftp|
        sftp.upload!(local_path, "/files")
    end
 end

end

Here is the error I get:这是我得到的错误:

Net::SFTP::StatusException: Net::SFTP::StatusException open /files (3, "permission denied")

/net-sftp-2.1.2/lib/net/sftp/operations/upload.rb:321:in `on_open'
/net-sftp-2.1.2/lib/net/sftp/request.rb:87:in `call'
/net-sftp-2.1.2/lib/net/sftp/request.rb:87:in `respond_to'
/net-sftp-2.1.2/lib/net/sftp/session.rb:948:in `dispatch_request'
/net-sftp-2.1.2/lib/net/sftp/session.rb:911:in `when_channel_polled'

I've also tried '~/' , '~' and '~/files' as the remote path, all of which I have access too.我也尝试过'~/''~''~/files'作为远程路径,我也可以访问所有这些路径。

While it's not clear from the documentation, all the examples for net-sftp and even the source code suggest that the remote path must be a full path to the remote file, not just a path to a folder to upload the file to.虽然从文档中不清楚,但 net-sftp 的所有示例甚至源代码都表明远程路径必须是远程文件的完整路径,而不仅仅是将文件上传到的文件夹的路径。 Ie /files/uploaded_file.txt , not just /files ./files/uploaded_file.txt ,而不仅仅是/files

What probably happens is that the server tries to open the folder ( / or /files ) as a file for writing, what fails.可能发生的情况是服务器尝试打开文件夹( //files )作为写入文件,但失败了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM