2011-08-24 126 views
7

我試圖用Ruby文件上傳到我的SFTP,我可以ssh中,一切都很好,但我的腳本失敗....這裏是我的小腳本紅寶石SFTP錯誤

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) 

任何想法我做錯了

回答

14

我使用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/move_me.txt") 
end 

在文檔中,示例使用遠程路徑來存檔,而不僅僅是目錄。

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

1

看來,一個目錄的上傳首先嚐試的mkdir是目標目錄。

如果該目標目錄已經存在,那麼mkdir會按照原始示例中的示例進行失敗。我仍然在尋找一種方法來使用內置的上傳目錄 - 同時,我的程序遍歷本地目錄,並單獨上傳每個文件。