2013-07-24 90 views
1

我有一個rake任務,它設置爲使用nets/scp gem從遠程服務器獲取文件夾。 我的Gemfile:Rails Net :: SCP文件傳輸

gem "net-ssh" 
gem "net-scp" 

我的代碼:

require 'net/scp' 
desc "Fetch hadoop data" 
task :fetch_data => :environment do 
Net::SCP.download!("server_name", "user", 
    "/home/dashboard/data", "#{Rails.root}/lib/tasks", 
    :password => "password1") 
end 

我得到的錯誤:SCP did not finish successfully (1)

如何將文件夾保存到我的軌道任務目錄,我怎麼能打印出更關於什麼導致scp出錯的信息?另外,我有我id_rsa鑰匙保存在我知道

回答

4

最後我用不同的方法來使用scp在文件:

require 'net/ssh' 
require 'net/scp' 

    desc "Fetch hadoop data" 
    task :fetch_data => :environment do 
    date_yesterday = (DateTime.now - 1.days).strftime("%Y%m%d") 
    date_today = (DateTime.now).strftime("%Y%m%d") 
    Net::SSH.start("server_name", "user",:password => "*****") do |session| 
     session.scp.download!("path_to_file_on_remote", "/home/rails_app/lib/tasks/folder", :recursive => true) 
    end 
    end