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
I had this issue today. Turns out my local file (in your example, source) pointed at a non-existent file. Good luck.
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
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")
Just for completeness' sake, this can also happen if you don't have proper permissions to write to the destination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With