Class: Capissh::FileTransfers
- Inherits:
-
Object
- Object
- Capissh::FileTransfers
- Defined in:
- lib/capissh/file_transfers.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#connection_manager ⇒ Object
readonly
Returns the value of attribute connection_manager.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #download(servers, from, to, options = {}, &block) ⇒ Object
-
#get(servers, 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.
-
#initialize(configuration, connection_manager, options = {}) ⇒ FileTransfers
constructor
A new instance of FileTransfers.
-
#put(servers, data, path, options = {}) ⇒ Object
Store the given data at the given location on all servers targetted by the current task.
- #transfer(servers, direction, from, to, options = {}, &block) ⇒ Object
- #upload(servers, from, to, options = {}, &block) ⇒ Object
Constructor Details
#initialize(configuration, connection_manager, options = {}) ⇒ FileTransfers
Returns a new instance of FileTransfers.
7 8 9 10 11 |
# File 'lib/capissh/file_transfers.rb', line 7 def initialize(configuration, connection_manager, ={}) @configuration = configuration @connection_manager = connection_manager @logger = [:logger] end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/capissh/file_transfers.rb', line 5 def configuration @configuration end |
#connection_manager ⇒ Object (readonly)
Returns the value of attribute connection_manager.
5 6 7 |
# File 'lib/capissh/file_transfers.rb', line 5 def connection_manager @connection_manager end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/capissh/file_transfers.rb', line 5 def logger @logger end |
Instance Method Details
#download(servers, from, to, options = {}, &block) ⇒ Object
40 41 42 |
# File 'lib/capissh/file_transfers.rb', line 40 def download(servers, from, to, ={}, &block) transfer(servers, :down, from, to, , &block) end |
#get(servers, 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.
Pass only one server, or the first of the set of servers will be used.
get server, “#deploy_to/current/log/production.log”, “log/production.log.web”
26 27 28 |
# File 'lib/capissh/file_transfers.rb', line 26 def get(servers, remote_path, path, ={}, &block) download(Array(servers).slice(0,1), remote_path, path, , &block) end |
#put(servers, 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.
16 17 18 |
# File 'lib/capissh/file_transfers.rb', line 16 def put(servers, data, path, ={}) upload(servers, StringIO.new(data), path, ) end |
#transfer(servers, direction, from, to, options = {}, &block) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/capissh/file_transfers.rb', line 44 def transfer(servers, direction, from, to, ={}, &block) if configuration.dry_run return logger.debug "transfering: #{[direction, from, to] * ', '}" end connection_manager.execute_on_servers(servers, ) do |sessions| Transfer.process(direction, from, to, sessions, .merge(:logger => logger), &block) end end |
#upload(servers, from, to, options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/capissh/file_transfers.rb', line 30 def upload(servers, from, to, ={}, &block) opts = .dup mode = opts.delete(:mode) transfer(servers, :up, from, to, opts, &block) if mode mode = mode.is_a?(Numeric) ? mode.to_s(8) : mode.to_s configuration.run servers, "chmod #{mode} #{to}", opts end end |