ruby sftp 错误
我正在尝试使用 ruby 将文件上传到我的 sftp,我可以 ssh 输入,一切都很好,但我的脚本失败了......这是我的小脚本,
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
但我不断收到此错误
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)
任何想法我做错了什么
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信使用 sftp 时,必须指定目标文件。
在文档中,示例使用文件的远程路径,而不仅仅是目录。
http://net-ssh.github.com/sftp/ v2/api/classes/Net/SFTP/Operations/Upload.html
I believe when using sftp, the destination file must be specified.
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
看起来目录的上传会首先尝试 mkdir 该目标目录。
如果该目标目录已存在,则 mkdir 将按照原始文件中给出的示例失败。我仍在寻找一种使用内置上传目录的方法——同时,我的程序遍历本地目录,并单独上传每个文件。
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.