| | 261 | end |
|---|
| | 262 | end |
|---|
| | 263 | end |
|---|
| | 264 | |
|---|
| | 265 | # Get file remote_path from FIRST server targetted by |
|---|
| | 266 | # the current task and transfer it to local machine as path. It will use |
|---|
| | 267 | # SFTP if Net::SFTP is installed; otherwise it will fall back to using |
|---|
| | 268 | # 'cat', which may cause corruption in binary files. |
|---|
| | 269 | # |
|---|
| | 270 | # get "#{deploy_to}/current/log/production.log", "log/production.log.web" |
|---|
| | 271 | def get(remote_path, path, options = {}) |
|---|
| | 272 | if Capistrano::SFTP && options.fetch(:sftp, true) |
|---|
| | 273 | execute_on_servers(options.merge(:once => true)) do |servers| |
|---|
| | 274 | logger.debug "downloading #{servers.first}:#{remote_path} to #{path}" |
|---|
| | 275 | sessions[servers.first].sftp.connect do |tsftp| |
|---|
| | 276 | tsftp.get_file remote_path, path |
|---|
| | 277 | end |
|---|
| | 278 | logger.trace "download finished" |
|---|
| | 279 | end |
|---|
| | 280 | else |
|---|
| | 281 | logger.important "Net::SFTP is not available; using remote 'cat' to get file, which may cause file corruption" |
|---|
| | 282 | File.open(path, "w") do |destination| |
|---|
| | 283 | run "cat #{remote_path}", :once => true do |ch, stream, data| |
|---|
| | 284 | case stream |
|---|
| | 285 | when :out then destination << data |
|---|
| | 286 | when :err then raise "error while downloading #{remote_path}: #{data.inspect}" |
|---|
| | 287 | end |
|---|
| | 288 | end |
|---|