From: Hugh Sasse Date: 2006-11-09T02:39:12+09:00 Subject: Re: Net::SSH Data Stream Problem On Thu, 9 Nov 2006, Andrew Stewart wrote: > Hello, > > I am trying to copy a file from my local machine to a remote machine using what platform(s)? > 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 [...] > 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 } # I suspect this should be: open(source_path, 'rb') { |f| stdin.write f.read } # so that that ctrl-Z isn't treated as EOF, or something ghastly # of that sort. > puts "done." > end > end > > Net::SSH.start(host, :username => user) do |session| > copy_file session, my_file, my_file.sub(/^.*\//, "#{upload_dir}") > end Hugh