Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby sftp error

i am trying to use ruby to upload a file to my sftp and I can ssh in and all is well but my script is failing ....here is my small script

require 'rubygems'
require 'net/sftp'

Net::SFTP.start('50.5.54.77', 'root', :password => 'PASSWORD') do |sftp|
  # upload a file or directory to the remote host
  sftp.upload!("/Users/tamer/sites/sandbox/move_me.txt", "/home")
end

but i keep getting this error

 ruby sftp.rb 
/Library/Ruby/Gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/operations/upload.rb:313:in `on_open': 
Net::SFTP::StatusException open /srv (4, "failure") (Net::SFTP::StatusException)

Any ideas what i am doing wrong

like image 925
Matt Elhotiby Avatar asked Aug 24 '11 16:08

Matt Elhotiby


2 Answers

I believe when using sftp, the destination file must be specified.

Net::SFTP.start('50.5.54.77', 'root', :password => 'PASSWORD') do |sftp|
  # upload a file or directory to the remote host
  sftp.upload!("/Users/tamer/sites/sandbox/move_me.txt", "/home/move_me.txt")
end

In the documentation, the examples use a remote path to file, not just the directory.

http://net-ssh.github.com/sftp/v2/api/classes/Net/SFTP/Operations/Upload.html

like image 174
Gazler Avatar answered Sep 25 '22 07:09

Gazler


It appears that the upload of a directory tries to mkdir that destination directory first.

If that destination directory already exists, the mkdir fails as per the example given in the original. I'm still looking for a way to use the built in upload a directory -- meanwhile, my program walks the local directory, and uploads each file individually.

like image 39
Harrison Avatar answered Sep 23 '22 07:09

Harrison