Sha256: 211fd84c4c0121e766d543ffa98f00ec26e47bae85d25d72dd91d68b7e61f374

Contents?: true

Size: 1.66 KB

Versions: 5

Compression:

Stored size: 1.66 KB

Contents

require 'toolshed/server_administration/ssh'
require 'toolshed/password'

require 'net/scp'
require 'ruby-progressbar'

module Toolshed
  module ServerAdministration
    # Handles SCP file from one place to another
    class SCP
      include Toolshed::Password

      attr_reader :local_path, :password, :remote_host, :remote_path, :ssh_options, :username, :verbose_output # rubocop:disable LineLength

      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

      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

      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

      private

      def on_complete
        Toolshed.logger.info ''
        Toolshed.logger.info 'SCP file transfer has completed.'
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
toolshed-1.0.12 lib/toolshed/server_administration/scp.rb
toolshed-1.0.11 lib/toolshed/server_administration/scp.rb
toolshed-1.0.10 lib/toolshed/server_administration/scp.rb
toolshed-1.0.9 lib/toolshed/server_administration/scp.rb
toolshed-1.0.8 lib/toolshed/server_administration/scp.rb