On Thu, 9 Nov 2006, Andrew Stewart wrote:

> 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'
>

does this help?

> 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 }
      stdin.flush
      stdin.close_write
      stdout.read
      stderr.read

>    puts "done."
>  end
> end



-a
-- 
my religion is very simple.  my religion is kindness. -- the dalai lama