I have this in 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
It appears to do the authentication step correctly (I can list files in a directory etc) but when I do the upload!
command like above it returns:
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!'
I also tried
# open and write to a pseudo-IO for a remote file
sftp.file.open("/test.txt", "wb") do |f|
f.puts "testing"
end
To try writing a binary file, but no luck.
Any ideas? Thanks!
Well I found a solution but I have no idea why it works.
Just playing around I added
sftp.dir.foreach("/") {|e| puts e.name }
right before theupload!
and it worked!So it looks like this now.
Doing a
dir
shouldn't have any effect, but for some reason it does. If anyone has some insight on this I'd be curious. Thanks!Btw, the ftp server identifies itself as "SSH-2.0-Maverick_SSHD" for what it's worth.