copying files to remote machine

Discussion in 'Ruby' started by Tim McIntyre, Jun 27, 2007.

  1. Tim McIntyre

    Tim McIntyre Guest

    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!
    Tim McIntyre, Jun 27, 2007
    1. Advertisements

  2. Tim McIntyre

    Greg Guest

    This issue has been discussed on the mail list before. I would
    recommend using ftp or sftp if possible, otherwise search the list!
    Greg, Jun 28, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.