Matt Elhotiby
Matt Elhotiby

Reputation: 44066

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

Upvotes: 10

Views: 10139

Answers (2)

Harrison
Harrison

Reputation: 11

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.

Upvotes: 1

Gazler
Gazler

Reputation: 84140

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

Upvotes: 20

Related Questions