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
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
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.
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