Class: Toolshed::ServerAdministration::SCP

Inherits:
Object
  • Object
show all
Includes:
Password
Defined in:
lib/toolshed/server_administration/scp.rb

Overview

Handles SCP file from one place to another

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Password

#password_from_config

Constructor Details

#initialize(options = nil) ⇒ SCP

Returns a new instance of SCP.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/toolshed/server_administration/scp.rb', line 15

def initialize(options = nil)
  options ||= {}
  @password = options[:password]
  @remote_host = options[:remote_host]
  @remote_path = options[:remote_path]
  @local_path = options[:local_path]
  @username = options[:username]
  @verbose_output = options[:verbose_output]
  @ssh_options = options[:ssh_options]
  @ssh_options ||= {}
  @ssh_options.merge(password: password_from_config(password))
end

Instance Attribute Details

#local_pathObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def local_path
  @local_path
end

#passwordObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def password
  @password
end

#remote_hostObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def remote_host
  @remote_host
end

#remote_pathObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def remote_path
  @remote_path
end

#ssh_optionsObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def ssh_options
  @ssh_options
end

#usernameObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def username
  @username
end

#verbose_outputObject (readonly)

rubocop:disable LineLength



13
14
15
# File 'lib/toolshed/server_administration/scp.rb', line 13

def verbose_output
  @verbose_output
end

Instance Method Details

#downloadObject



28
29
30
31
32
# File 'lib/toolshed/server_administration/scp.rb', line 28

def download
  Toolshed.logger.info "Attempting to SCP from #{username}@#{remote_host}:#{remote_path} to #{local_path}." # rubocop:disable LineLength
  Net::SCP.download!(remote_host, username, remote_path, local_path, ssh: ssh_options, recursive: true) # rubocop:disable LineLength
  on_complete
end

#uploadObject



34
35
36
37
38
# File 'lib/toolshed/server_administration/scp.rb', line 34

def upload
  Toolshed.logger.info "Attempting to SCP from #{local_path} to #{username}@#{remote_host}:#{remote_path}." # rubocop:disable LineLength
  Net::SCP.upload!(remote_host, username, local_path, remote_path, ssh: ssh_options, recursive: true) # rubocop:disable LineLength
  on_complete
end