From 8ad8264d7aca81c1a119e5010e63dbdf09d950e4 Mon Sep 17 00:00:00 2001 From: Christoph Schiessl Date: Fri, 9 Dec 2011 14:14:53 +0100 Subject: [PATCH] implement #scp_download method to allow downloads in addition to uploads via scp. alias #scp method as #scp_upload. --- lib/fog/compute/models/server.rb | 11 +++++++++++ lib/fog/core/scp.rb | 20 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/fog/compute/models/server.rb b/lib/fog/compute/models/server.rb index dfaf78a31..53038a89d 100644 --- a/lib/fog/compute/models/server.rb +++ b/lib/fog/compute/models/server.rb @@ -13,6 +13,17 @@ module Fog Fog::SCP.new(public_ip_address, username, scp_options).upload(local_path, remote_path, upload_options) end + alias_method :scp_upload, :scp + + def scp_download(remote_path, local_path, download_options = {}) + require 'net/scp' + requires :public_ip_address, :username + + scp_options = {} + scp_options[:key_data] = [private_key] if private_key + Fog::SCP.new(public_ip_address, username, scp_options).download(remote_path, local_path, download_options) + end + def ssh(commands, options={}) require 'net/ssh' requires :public_ip_address, :username diff --git a/lib/fog/core/scp.rb b/lib/fog/core/scp.rb index e341ba790..600ec90a7 100644 --- a/lib/fog/core/scp.rb +++ b/lib/fog/core/scp.rb @@ -27,6 +27,10 @@ module Fog Fog::Mock.not_implemented end + def download(remote_path, local_path, download_options = {}) + Fog::Mock.not_implemented + end + end class Real @@ -45,10 +49,22 @@ module Fog @options = { :paranoid => false }.merge(options) end - def upload(local_path, remote_path, upload_options = {} ) + def upload(local_path, remote_path, upload_options = {}) begin Net::SCP.start(@address, @username, @options) do |scp| - scp.upload!(local_path, remote_path, upload_options ) do |ch, name, sent, total| + scp.upload!(local_path, remote_path, upload_options) do |ch, name, sent, total| + # TODO: handle progress display? + end + end + rescue Exception => error + raise error + end + end + + def download(remote_path, local_path, download_options = {}) + begin + Net::SCP.start(@address, @username, @options) do |scp| + scp.download!(remote_path, local_path, download_options) do |ch, name, sent, total| # TODO: handle progress display? end end