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
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, login, password) begin Timeout::timeout(2) do # use a persistent connection to transfer files Net::SCP.start(host, login, :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.) 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.) raise e end return "Upload the file '#{file_name}' to a remote server '#{host}'...\n" end |