net :: sftp :: statusexception(5,“不良消息”)发送大文件的块时:

发布于 2025-02-05 18:20:08 字数 1657 浏览 4 评论 0原文

简短版本:

中发送文件 sftp 服务器在net :: sftp :: statusexception(stateusexception)中失败( 5,“坏消息”)错误。

长版本:

我正在尝试将我的 ror 应用程序从客户的 sftp 服务器发送。

我正在使用Fog :: Storage当我从s3服务器中读取文件时。

这是我的示例代码:

file_paths = get_file_names()
Net::SFTP.start(sftp_domain, sftp_user, :password => sftp_password) do |sftp|
  file_paths.each do |file_to_upload|
    filename = nil
    if Rails.env == "production"
      filename = file_to_upload.file.path.split("/").last
                            
      # Create S3 Connection:
      connection = Fog::Storage.new(provider: 'AWS'...)

      # Find root directory:
      bucket = connection.directories.get(ENV['MY_S3'])

      # Send all files in directory, chunk-by-chunk:
      sftp.file.open(sftp_folder + "/" + filename, "w") do |sftp_file|
        bucket.files.get(file_to_upload.file.path) do |chunk|
          sftp_file.write(chunk)
        end
      end
    end
  end

当单个文件超过默认块大小时,我会收到以下错误:

Excon::Error::Socket: Net::SFTP::StatusException (5, "bad message") (Net::SFTP::StatusException)

更多详细信息:

  • 使用Rails 4.2.5.1.1。
  • 使用Ruby 2.3.4P301(2017-03-30修订58214)[AARCH64-LINUX]
  • GEM锁定在Net-SFTP(3.0.0)和Net-SSH(6.1.0)上。
  • 足够小的文件可以正确发送 块 - 正确发送。

我尝试过的内容:

  • 执行编码行不通(同样的错误)。
  • 在一个块中读取大文件无效(内存错误)。

我很乐意根据需要添加更多详细信息,对不起,如果我错过了什么!

事先感谢大家!

Short Version:

Sending files from S3 in more than one chunk to SFTP server fails with a Net::SFTP::StatusException (5, "bad message") error.

Long Version:

I'm trying to send a large file from my RoR application to a customer's SFTP server.

I'm using Fog::Storage as I'm reading the file from my S3 server.

Here is my example code:

file_paths = get_file_names()
Net::SFTP.start(sftp_domain, sftp_user, :password => sftp_password) do |sftp|
  file_paths.each do |file_to_upload|
    filename = nil
    if Rails.env == "production"
      filename = file_to_upload.file.path.split("/").last
                            
      # Create S3 Connection:
      connection = Fog::Storage.new(provider: 'AWS'...)

      # Find root directory:
      bucket = connection.directories.get(ENV['MY_S3'])

      # Send all files in directory, chunk-by-chunk:
      sftp.file.open(sftp_folder + "/" + filename, "w") do |sftp_file|
        bucket.files.get(file_to_upload.file.path) do |chunk|
          sftp_file.write(chunk)
        end
      end
    end
  end

ONLY when a single file exceeds the default chunk-size, I get the following error:

Excon::Error::Socket: Net::SFTP::StatusException (5, "bad message") (Net::SFTP::StatusException)

More details:

  • Using rails 4.2.5.1.
  • Using ruby 2.3.4p301 (2017-03-30 revision 58214) [aarch64-linux]
  • Gem locked at net-sftp (3.0.0) and net-ssh (6.1.0).
  • Files that are small enough to be sent in one chunk - are sent correctly.

What I tried:

  • enforcing an encoding didn't work (same error).
  • reading the large file in one chunk did not work (memory error).

I will be happy to add more details as needed, sorry if I missed something!

Thanks in advance to everyone!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文