Reputation: 71
My code
IMAGE_DIR = 'D:\File_Server\Nisa_Costcutter\Master Nisa CC Logos'
require 'net/ssh'
require 'net/scp'
def scopy_file(file)
puts "Transferring #{file.path}"
Net::SCP.upload!('192.168.254.5',
'passenger',
file,
'/var/www/pinpointlms.co.uk/shared/logos',
:ssh => {password: '*****'})
end
puts "Starting Upload"
Dir.foreach(IMAGE_DIR) do |name|
if name.length > 4 && name[-4..-1].upcase == '.BMP'
filename=name.strip()
file = File.new(File.join(IMAGE_DIR, filename))
if (Time.now - file.mtime) > 86400
scopy_file(file)
end
end
end
puts "End of Transfer"
I am trying to copy some files from a windows box to an Ubuntu box using Ruby but I get the following output:
Starting Upload
Transferring D:\File_Server\Nisa_Costcutter\Master Nisa CC Logos/Z2579.BMP
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:359:in `block (3 levels) in start_command': SCP did not finish successfully (1)
(Net::SCP::Error) from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:591:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/channel.rb:591:in `do_close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:586:in `channel_close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:465:in `dispatch_incoming_packets'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:221:in `preprocess'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:205:in `process'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `block in loop'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:169:in `loop'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-ssh-2.8.0/lib/net/ssh/connection/session.rb:118:in `close'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:205:in `ensure in start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:205:in `start'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/net-scp-1.1.2/lib/net/scp.rb:221:in `upload!'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:8:in `scopy_file'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:24:in`block in <main>'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:17:in`foreach'
from C:/Users/administrator.GASKANDHAWLEY/Desktop/copy_images2.rb:17:in
`'
I am a ruby beginner so any help you can give me on how to debug this code further will be much appreciated.
Thanks
Upvotes: 1
Views: 3535
Reputation: 3552
In case it's helpful for others, I got the exact same error as this when trying to upload a file to a path that didn't yet exist. scp from shell will allow you to do this, but Net::SCP will fail with this error.
i.e.
scp "my.file" "/foo/bar/"
if /foo exists but /foo/bar/ does not, scp will create /foo/bar and put your file there (assuming permissions allow you to do this).
However - under the same circumstances - this will fail with the error given in the question
scp.upload!(my_file, "/foo/bar/")
The only solution I've found is to first create the path you want locally, and then upload with the :recursive option on, like so:
scp.upload!("bar/", "/foo" :recursive => true)
where ./bar contains my_file.
Upvotes: 1
Reputation: 1559
You probably don't have user access to upload (write) that file in the given directory '/var/www/pinpointlms.co.uk/shared/logos' on your Ubuntu server.
Try to save it without giving it a full path, so it ends up in the user's home directory on the Ubuntu server. If this will work, then your problem is related with the user permission on the server.
Upvotes: 1