Module: Capistrano::Configuration::Actions::FileTransfer

Included in:
Capistrano::Configuration
Defined in:
lib/capistrano/configuration/actions/file_transfer.rb

Instance Method Summary collapse

Instance Method Details

#download(from, to, options = {}, &block) ⇒ Object



33
34
35
# File 'lib/capistrano/configuration/actions/file_transfer.rb', line 33

def download(from, to, options={}, &block)
  transfer(:down, from, to, options, &block)
end

#get(remote_path, path, options = {}, &block) ⇒ Object

Get file remote_path from FIRST server targeted by the current task and transfer it to local machine as path.

get “#deploy_to/current/log/production.log”, “log/production.log.web”



20
21
22
# File 'lib/capistrano/configuration/actions/file_transfer.rb', line 20

def get(remote_path, path, options={}, &block)
  download(remote_path, path, options.merge(:once => true), &block)
end

#put(data, path, options = {}) ⇒ Object

Store the given data at the given location on all servers targetted by the current task. If :mode is specified it is used to set the mode on the file.



11
12
13
14
# File 'lib/capistrano/configuration/actions/file_transfer.rb', line 11

def put(data, path, options={})
  opts = options.dup
  upload(StringIO.new(data), path, opts)
end

#transfer(direction, from, to, options = {}, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/capistrano/configuration/actions/file_transfer.rb', line 37

def transfer(direction, from, to, options={}, &block)
  if dry_run
    logger.debug "#{direction}load #{from.is_a?(StringIO) ? "string" : from} to #{to.is_a?(StringIO) ? "string" : to} via #{options.fetch(:via, :sftp)}"
    return
  end
  
  execute_on_servers(options) do |servers|
    targets = servers.map { |s| sessions[s] }
    Transfer.process(direction, from, to, targets, options.merge(:logger => logger), &block)
  end
end

#upload(from, to, options = {}, &block) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/capistrano/configuration/actions/file_transfer.rb', line 24

def upload(from, to, options={}, &block)
  mode = options.delete(:mode)
  transfer(:up, from, to, options, &block)
  if mode
    mode = mode.is_a?(Numeric) ? mode.to_s(8) : mode.to_s
    run "chmod #{mode} #{to}"
  end
end