Class: Bow::Ssh::Scp

Inherits:
Object
  • Object
show all
Defined in:
lib/bow/ssh/scp.rb

Instance Method Summary collapse

Constructor Details

#initialize(ssh_helper) ⇒ Scp

Returns a new instance of Scp.



6
7
8
# File 'lib/bow/ssh/scp.rb', line 6

def initialize(ssh_helper)
  @ssh_helper = ssh_helper
end

Instance Method Details

#call(source, target) ⇒ Object



10
11
12
13
14
# File 'lib/bow/ssh/scp.rb', line 10

def call(source, target)
  @ssh_helper.execute(cmd_rm(target)) if cleanup_needed?
  @ssh_helper.run(cmd_scp(source, target))
  @ssh_helper.run(cmd)
end

#cleanup_needed?(source, target) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/bow/ssh/scp.rb', line 29

def cleanup_needed?(source, target)
  File.basename(source) == File.basename(target)
end

#cmd_rm(target) ⇒ Object



25
26
27
# File 'lib/bow/ssh/scp.rb', line 25

def cmd_rm(target)
  format('rm -rf %s', target)
end

#cmd_scp(source, target) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/bow/ssh/scp.rb', line 16

def cmd_scp(source, target)
  format(
    'scp -o ConnectTimeout -r %s %s:%s',
    source,
    @ssh_helper.conn,
    target
  )
end