Method: Receiver::CrowbarShellAPI#upload_file

Defined in:
lib/receiver/crowbar_shell_api.rb

#upload_file(file_name, file_path, destination_path, host, login, password) ⇒ Object

Upload a file to a remote server

Parameters:

  • file_name

    The name of the file

  • file_path

    The path of the file

  • destination_path

    The destination path to upload

  • host

    The ip of the host

  • login

    The login of the host

  • password

    The password of the host

Raises:

  • SCPError

  • TimeoutError

Author:

  • mbretaud



557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/receiver/crowbar_shell_api.rb', line 557

def upload_file(file_name, file_path, destination_path, host, , password)
  begin
    Timeout::timeout(2) do
      # use a persistent connection to transfer files
      Net::SCP.start(host, , :password => password) do |scp|
        begin
          # upload a file to a remote server
          scp.upload! "#{file_path}/#{file_name}", destination_path
          @logger.info("Receiver::CrowbarShellApi   Upload the file '#{file_name}' to a remote server '#{host}'...")
        rescue Net::SCP::Error => e
          @logger.info("Receiver::CrowbarShellApi   Error: Upload the file '#{file_name}' to a remote server '#{host}'.")
          @logger.debug(e.message)
          raise e
        end
      end
    end
  rescue Timeout::Error => e
    @logger.info("Receiver::CrowbarShellApi   Error: Timed out trying to get a connection to upload the file '#{file_name}'.")
    @logger.debug(e.message)
    raise e
  end
  return "Upload the file '#{file_name}' to a remote server '#{host}'...\n"
end