Class: Fog::SCP::Real
- Inherits:
-
Object
- Object
- Fog::SCP::Real
- Defined in:
- lib/fog/core/scp.rb
Instance Method Summary collapse
- #download(remote_path, local_path, download_options = {}, &block) ⇒ Object
-
#initialize(address, username, options) ⇒ Real
constructor
A new instance of Real.
- #upload(local_path, remote_path, upload_options = {}, &block) ⇒ Object
Constructor Details
#initialize(address, username, options) ⇒ Real
Returns a new instance of Real.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/fog/core/scp.rb', line 46 def initialize(address, username, ) begin require "net/scp" rescue LoadError Fog::Logger.warning("'net/scp' missing, please install and try again.") exit(1) end key_manager = Net::SSH::Authentication::KeyManager.new(nil, ) unless [:key_data] || [:keys] || [:password] || key_manager.agent raise ArgumentError, ":key_data, :keys, :password or a loaded ssh-agent is required to initialize SSH" end [:timeout] = 30 if [:key_data] || [:keys] [:keys_only] = true # Explicitly set these so net-ssh doesn't add the default keys # as seen at https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/authentication/session.rb#L131-146 [:keys] = [] unless [:keys] [:key_data] = [] unless [:key_data] end @address = address @username = username @options = { paranoid: false, verify_host_key: :never }.merge() @options.delete(:paranoid) if Net::SSH::VALID_OPTIONS.include? :verify_host_key @options[:verify_host_key] = false unless Net::SSH::Verifiers.const_defined?(:Never) end |
Instance Method Details
#download(remote_path, local_path, download_options = {}, &block) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/fog/core/scp.rb', line 86 def download(remote_path, local_path, = {}, &block) Net::SCP.start(@address, @username, @options) do |scp| scp.download!(remote_path, local_path, ) do |ch, name, sent, total| block.call(ch, name, sent, total) if block end end rescue Exception => error raise error end |
#upload(local_path, remote_path, upload_options = {}, &block) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/core/scp.rb', line 76 def upload(local_path, remote_path, = {}, &block) Net::SCP.start(@address, @username, @options) do |scp| scp.upload!(local_path, remote_path, ) do |ch, name, sent, total| block.call(ch, name, sent, total) if block end end rescue Exception => error raise error end |