From: Andrew Stewart Date: 2006-11-09T02:28:03+09:00 Subject: Net::SSH Data Stream Problem Hello, I am trying to copy a file from my local machine to a remote machine using Net::SSH. The copy fails part way leaving the file partly written on the remote machine. The size of the remote file portion is always 131072 bytes (128 kB). My local file is ~1.2MB. This leads me to suspect that the data are being fed in chunks and something is going wrong after the first chunk -- though that's a guess. Here's the output: Copying /path/to/my/file.zip to /path/to/remote/directory/ file.zip...done. /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/ssh/transport/ session.rb:256:in `wait_for_message': disconnected: Received data for nonexistent channel 0. (2) (Net::SSH::Transport::Disconnect) from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/ ssh/transport/session.rb:240:in `wait_for_message' from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/ ssh/connection/driver.rb:148:in `process' from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/ ssh/connection/driver.rb:138:in `loop' from /usr/local/lib/ruby/gems/1.8/gems/net-ssh-1.0.9/lib/net/ ssh/service/process/popen3.rb:66:in `popen3' [snipped rest of trace] Interestingly the 'puts "...done."' line is executed before the error is thrown. Since session.process.popen3 is synchronous, does that not imply that the copy has finished? And here's the code (based on Ruby Cookbook recipe 14.11): require 'rubygems' require 'net/ssh' host = 'xyz.com' user = 'me' upload_dir = '/path/to/remote/directory/' my_file = '/path/to/my/file.zip' def copy_file(session, source_path, destination_path=nil) destination_path ||= source_path cmd = %{cat > "#{destination_path.gsub('"', '\"')}"} session.process.popen3 cmd do |stdin, stdout, stderr| print "Copying #{source_path} to #{destination_path}..." open(source_path) { |f| stdin.write f.read } puts "done." end end Net::SSH.start(host, :username => user) do |session| copy_file session, my_file, my_file.sub(/^.*\//, "#{upload_dir}") end I would greatly appreciate any help. Thanks and regards, Andy Stewart