gpt4 book ai didi

ruby SFTP 返回 "Net::SSH::Disconnect: disconnected: Failed to read binary packet data! (2)"

转载 作者:太空宇宙 更新时间:2023-11-03 16:06:25 32 4
gpt4 key购买 nike

我在 ruby​​ 1.9.3 中有这个:

Net::SFTP.start(ENV['SFTP_HOST'], ENV['SFTP_USERNAME'], password: ENV['SFTP_PASSWORD'], key_data: [ENV['SFTP_KEY']], keys_only: true) do |sftp|
sftp.upload!(StringIO.new("testing"), "/text.txt")
end

它似乎正确地执行了身份验证步骤(我可以列出目录中的文件等)但是当我像上面那样执行 upload! 命令时它返回:

Net::SSH::Disconnect: disconnected: Failed to read binary packet data! (2)
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/transport/session.rb:176:in `block in poll_message'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/transport/session.rb:166:in `loop'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/transport/session.rb:166:in `poll_message'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/connection/session.rb:451:in `dispatch_incoming_packets'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/connection/session.rb:213:in `preprocess'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/connection/session.rb:197:in `process'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/connection/session.rb:161:in `block in loop'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/connection/session.rb:161:in `loop'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-ssh-2.5.2/lib/net/ssh/connection/session.rb:161:in `loop'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:802:in `loop'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/operations/upload.rb:195:in `wait'
from /Users/barmstrong/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:103:in `upload!'

我也试过

    # open and write to a pseudo-IO for a remote file
sftp.file.open("/test.txt", "wb") do |f|
f.puts "testing"
end

尝试编写一个二进制文件,但没有运气。

有什么想法吗?谢谢!

最佳答案

嗯,我找到了一个解决方案,但我不知道它为什么有效。

只是玩玩我添加了 sftp.dir.foreach("/") {|e|将 e.name 放在 upload 之前! 成功了!

所以现在看起来像这样。

Net::SFTP.start(ENV['SFTP_HOST'], ENV['SFTP_USERNAME'], password: ENV['SFTP_PASSWORD'], key_data: [ENV['SFTP_KEY']], keys_only: true) do |sftp|
sftp.dir.foreach("/") {}
sftp.upload!(StringIO.new("testing"), "/text.txt")
end

执行 dir 应该不会有任何影响,但出于某种原因它确实有影响。如果有人对此有所了解,我会很好奇。谢谢!

顺便说一句,ftp 服务器将自己标识为“SSH-2.0-Maverick_SSHD”,这是值得的。

关于 ruby SFTP 返回 "Net::SSH::Disconnect: disconnected: Failed to read binary packet data! (2)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12847202/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com