On 8 Nov 2006, at 18:32, Hugh Sasse wrote:

> I'd read then write q bytes at a time until the whole file is read
> I think the value for q is the length of the file you ended up with
> at the far end.  That would make  a good start for a search, anyway.

Thanks for the suggestion -- it worked.  Here are the code changes  
(based on Ruby Cookbook recipe 6.6):

I added:

class File
   def each_chunk(chunk_size=1024)
     yield read(chunk_size) until eof?
   end
end

And I changed:

     open(source_path) { |f| stdin.write f.read }

To:

     open(source_path) { |f|
       f.each_chunk { |chunk| stdin.write chunk  }
     }

I tried various chunk sizes descending from 128kB, the size which  
made it over the wire previously.  The failures remained until the  
chunk size was 1024 bytes.

The overall speed was comparable with scp from the shell.

Thanks for your help,
Andy