Class: RHC::Commands::Scp
- Includes:
- SCPHelpers
- Defined in:
- lib/rhc/commands/scp.rb
Constant Summary
Constants included from Helpers
Helpers::BOUND_WARNING, Helpers::PREFIX, Helpers::ROLES
Instance Method Summary collapse
Methods included from SSHHelpers
#check_ssh_executable!, #exe?, #fingerprint_for_default_key, #fingerprint_for_local_key, #generate_ssh_key_ruby, #has_ssh?, #restore_snapshot, #run_on_gears, #save_snapshot, #ssh_command_for_op, #ssh_key_triple_for, #ssh_key_triple_for_default_key, #ssh_keygen_fallback, #ssh_ruby, #ssh_send_file_ruby, #ssh_send_url_ruby, #ssh_version, #table_from_gears
Methods inherited from Base
Methods included from RHC::ContextHelpers
#find_app, #find_domain, #find_membership_container, #find_team, #from_local_git, included, #namespace_context, #server_context
Methods included from GitHelpers
#git_clone_application, #git_clone_deploy_hooks, #git_clone_repo, #git_cmd, #git_config_get, #git_config_set, #git_remote_add, #git_version, #has_git?
Methods included from Helpers
#agree, #certificate_file, #client_from_options, #collect_env_vars, #color, #confirm_action, #date, #datetime_rfc3339, #debug, #debug?, #debug_error, #decode_json, #deprecated, #deprecated_command, #disable_deprecated?, #distance_of_time_in_words, #env_var_regex_pattern, #error, #exec, #host_exists?, #hosts_file_contains?, #human_size, #info, #interactive?, #jruby?, #mac?, #openshift_online_server?, #openshift_rest_endpoint, #openshift_server, #openshift_url, #pluralize, #results, #role_name, #run_with_tee, #ssh_string, #ssh_string_parts, #ssl_options, #success, #system_path, #table_heading, #to_host, #to_uri, #token_for_user, #unix?, #user_agent, #warn, #windows?, #with_tolerant_encoding
Methods included from OutputHelpers
#default_display_env_var, #display_app, #display_app_configurations, #display_authorization, #display_cart, #display_cart_storage_info, #display_cart_storage_list, #display_deployment, #display_deployment_list, #display_domain, #display_env_var_list, #display_key, #display_team, #format_cart_gears, #format_cart_header, #format_gear_info, #format_key_header, #format_scaling_info, #format_usage_message
Constructor Details
This class inherits a constructor from RHC::Commands::Base
Instance Method Details
#run(_, action, local_path, remote_path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rhc/commands/scp.rb', line 28 def run(_, action, local_path, remote_path) rest_app = find_app ssh_opts = rest_app.ssh_url.gsub("ssh://","").split("@") raise RHC::ArgumentNotValid.new("'#{action}' is not a valid argument for this command. Please use upload or download.") unless action == 'download' || action == 'upload' raise RHC::FileOrPathNotFound.new("Local file, file_path, or directory could not be found.") unless File.exist?(local_path) begin start_time = Time.now last_sent = nil Net::SCP.send("#{action}!".to_sym, ssh_opts[1], ssh_opts[0], (action == 'upload' ? local_path : remote_path), (action == 'upload' ? remote_path : local_path)) do |ch, name, sent, total| #:nocov: if sent != last_sent last_sent = sent complete = total == 0 ? 100 : ((sent.to_f/total.to_f)*100).to_i $stderr.print "\r #{action}ing #{name}: #{complete}% complete. #{sent}/#{total} bytes transferred " + (sent == total ? "in #{Time.now - start_time} seconds \n" : "") end #:nocov: end rescue Errno::ECONNREFUSED raise RHC::SSHConnectionRefused.new(ssh_opts[0], ssh_opts[1]) rescue SocketError => e raise RHC::ConnectionFailed, "The connection to #{ssh_opts[1]} failed: #{e.}" rescue Net::SSH::AuthenticationFailed => e debug_error e raise RHC::SSHAuthenticationFailed.new(ssh_opts[1], ssh_opts[0]) rescue Net::SCP::Error => e debug_error e raise RHC::RemoteFileOrPathNotFound.new("An unknown error occurred: #{e.}") end end |