3
A
回答
5
好的,我決定自己做。代碼不是很漂亮,因爲它包含了很多異常處理,但它完成了工作:)
require 'rake'
require 'net/ftp'
def ftp_files(prefixToRemove, sourceFileList, targetDir, hostname, username, password)
Net::FTP.open(hostname, username, password) do |ftp|
begin
puts "Creating dir #{targetDir}"
ftp.mkdir targetDir
rescue
puts $!
end
sourceFileList.each do |srcFile|
if prefixToRemove
targetFile = srcFile.pathmap(("%{^#{prefixToRemove},#{targetDir}}p"))
else
targetFile = srcFile.pathmap("#{targetDir}%s%p")
end
begin
puts "Creating dir #{targetFile}" if File.directory?(srcFile)
ftp.mkdir targetFile if File.directory?(srcFile)
rescue
puts $!
end
begin
puts "Copying #{srcFile} -> #{targetFile}" unless File.directory?(srcFile)
ftp.putbinaryfile(srcFile, targetFile) unless File.directory?(srcFile)
rescue
puts $!
end
end
end
end
task :ftp => [:dist] do
ftp_files("dist", FileList["dist/**/*"], "remote_dir", 'host.com', 'user', 'pwd')
end
4
不,我知道的雖然Net::SFTP寶石是相當不錯的,你可以寫一個new rake task很容易地做你喜歡什麼。
這也取決於你正在做什麼樣的部署 - 如果它的Rails,你看看Capistrano或Vlad the Deployer?
2
上面的代碼對我來說不起作用。我創建了不同的一個: https://gist.github.com/1690647
相關問題
- 1. 插件是否可用於rake任務?
- 2. 是否有像db:fixtures:load in factory_girl_rails這樣的內置rake任務?
- 3. 運行所有rake任務?
- 4. Rake任務只有一次
- 5. 是否有iOS 5.0的任何FTP服務器庫
- 6. 在Rake任務
- 7. rake任務
- 8. rake任務
- 9. Rake「variadic」任務
- 10. 是否有可能判斷環境是否已被傳入rake任務塊?
- 11. 是否有可能從Rails的另一臺服務器運行rake任務
- 12. 確定Rails服務器是否從rake任務運行
- 13. 其中是rake任務acts_as_taggable_on_engine:安裝:migrations是否定義?
- 14. 爲每個現有的rake任務定義一個自定義rake任務
- 15. Rake任務會破壞我的Ruby ...壞Rake任務
- 16. Rake任務的命令行工作,但失敗rake任務
- 17. 如何將Rake任務添加到默認的Rake任務?
- 18. Rake中的「環境」任務是什麼?
- 19. 運行rake任務
- 20. Rake任務失火
- 21. 守護rake任務
- 22. rake任務指定
- 23. rake任務問題
- 24. 調試rake任務
- 25. 訂單Rake任務
- 26. 如何rake任務
- 27. rake任務變量
- 28. 調度Rake任務
- 29. 測試Rake任務
- 30. rake任務訂購