Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::SCP::Error (SCP did not finish successfully ()):

I have a script which will do the file transfer from one server to another but it gives an error:

Net::SCP::Error (SCP did not finish successfully ()):

Can any body help me? Here is my code.

Net::SCP.start( 's.com', 'username', :password => 'password' ) do|scp|
  scp.upload!( source, destination )
end
like image 863
Shrikanth Hathwar Avatar asked Dec 16 '10 21:12

Shrikanth Hathwar


4 Answers

I had this issue today. Turns out my local file (in your example, source) pointed at a non-existent file. Good luck.

like image 132
rude-n8 Avatar answered Nov 19 '22 14:11

rude-n8


This error also happens if you are uploading a file to a folder that does not yet exist on the remote server. Folder creation is not implicit in SCP

like image 36
Evan Avatar answered Nov 19 '22 15:11

Evan


I had a slightly different error that included the exit code in parens:

Net::SCP::Error Exception: SCP did not finish successfully (1)

I figured at first this would have been caused by the source file not existing or the destination dir not existing as others have mentioned, but it turned out to be because I was passing a pathname object for the source file instead of a string.

my_file = Rails.root.join('config/my_file') # my_file.class => Pathname
scp.upload!(my_file,  "/var/tmp/dev.pub")

<Net::SCP::Error: SCP did not finish successfully (1)>
"gems/net-scp-1.0.4/lib/net/scp.rb:352:in `start_command'",                                                                                                                                                                                                   "gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb:590:in `call'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb:590:in `do_close'",                                                                                                                                                                                     "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:580:in `channel_close'",                                                                                                                                                                                "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:459:in `send'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:459:in `dispatch_incoming_packets'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:216:in `preprocess'",                                                                                                                                                                                   "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:200:in `process'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop'",                                                                                                                                                                                         "gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop_forever'",
"gems/net-ssh-2.6.7/lib/net/ssh/connection/session.rb:164:in `loop'",                                                                                                                                                                                         "gems/net-ssh-2.6.7/lib/net/ssh/connection/channel.rb:269:in `wait'",
"gems/net-scp-1.0.4/lib/net/scp.rb:279:in `upload!'",

The file was being copied to the correct remote location, but something in net-ssh was exiting 1 instead of 0, I haven't bothered to go find where that call is in the stack trace

# gems/net-scp-1.0.4/lib/net/scp:352
channel.on_close { |ch| raise Net::SCP::Error, "SCP did not finish successfully (#{ch[:exit]})" if ch[:exit] != 0 }

Just changing the pathname object a string made everything work

my_file = Rails.root.join('config/my_file').to_s
scp.upload!(my_file,  "/var/tmp/dev.pub")
like image 8
mmrobins Avatar answered Nov 19 '22 13:11

mmrobins


Just for completeness' sake, this can also happen if you don't have proper permissions to write to the destination.

like image 6
troelskn Avatar answered Nov 19 '22 15:11

troelskn