Forum: Ruby copying files to remote machine

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Tim M. (Guest)
on 2007-06-28 01:24
(Received via mailing list)
Hey all,

I've got a little script that is attempting to copy images to a
remote server.  The significant parts of the script were taken
directly from recipe 14.11 in the ruby cookbook.

relevant sections:

# directly from cookbook recipe 14.11
def remote_copy(session, source_path, destination_path=nil)
   destination_path ||= source_path
   cmd = %{cat > "#{destination_path.gsub('"', '\"')}"}
   cat_process =

   cat_process.on_success do |p|
     p.write(open(source_path) { |f| })
     puts "Copied #{source_path} to #{destination_path}."

# slightly modified from same recipe
('', :username=>'user', :password=>'pass') do |session|
   Film.find(:all).each do |film|
     if film.small_local_cover_image_exists?
       remote_copy(session, film.small_local_cover_path,


When I run it works for about the first 4 or 5 films then dies with
this message:

session.rb:258:in `wait_for_message': disconnected: Received data for
nonexistent channel 2. (2) (Net::SSH::Transport::Disconnect)
         from /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/
transport/session.rb:242:in `wait_for_message'
         from /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/
connection/driver.rb:148:in `process'
         from /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/
connection/driver.rb:138:in `loop'
         from /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/
session.rb:164:in `loop'
         from script/cron/move_images_to_static_server.rb:53
         from /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/
session.rb:127:in `initialize'
         from /usr/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/
ssh.rb:47:in `start'
         from script/cron/move_images_to_static_server.rb:37

ubuntu 6.06 "Dapper Drake" - ruby 1.8.4 - net-ssh 1.0.10

Thanks in advance for any help!
Greg (Guest)
on 2007-06-28 09:26
(Received via mailing list)
This issue has been discussed on the mail list before.  I would
recommend using ftp or sftp if possible, otherwise search the list!
This topic is locked and can not be replied to.