Class: SSHKit::Backend::Local

Inherits:
Abstract
  • Object
show all
Defined in:
lib/sshkit/backends/local.rb

Instance Attribute Summary

Attributes inherited from Abstract

#host

Instance Method Summary collapse

Methods inherited from Abstract

#as, #background, #capture, config, configure, #execute, #make, #rake, #redact, #run, #test, #with, #within

Constructor Details

#initialize(_ = nil, &block) ⇒ Local


9
10
11
# File 'lib/sshkit/backends/local.rb', line 9

def initialize(_ = nil, &block)
  super(Host.new(:local), &block)
end

Instance Method Details

#download!(remote, local = nil, _options = {}) ⇒ Object


28
29
30
31
32
33
34
35
36
37
# File 'lib/sshkit/backends/local.rb', line 28

def download!(remote, local=nil, _options = {})
  remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/") || pwd_path.nil?
  if local.nil?
    FileUtils.cp(remote, File.basename(remote))
  else
    File.open(remote, "rb") do |f|
      IO.copy_stream(f, local)
    end
  end
end

#upload!(local, remote, options = {}) ⇒ Object


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sshkit/backends/local.rb', line 13

def upload!(local, remote, options = {})
  remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/") || pwd_path.nil?
  if local.is_a?(String)
    if options[:recursive]
      FileUtils.cp_r(local, remote)
    else
      FileUtils.cp(local, remote)
    end
  else
    File.open(remote, "wb") do |f|
      IO.copy_stream(local, f)
    end
  end
end