我在 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
尝试编写二进制文件,但没有运气。
有任何想法吗?谢谢!