Skip to content

Instantly share code, notes, and snippets.

@paneq
Created January 24, 2013 15:32
Show Gist options
  • Save paneq/4623168 to your computer and use it in GitHub Desktop.
Save paneq/4623168 to your computer and use it in GitHub Desktop.
Vagrant SSH downloader
module Vagrant
module Downloaders
class SSH < Base
def self.match?(uri)
URI(uri).scheme == "ssh"
rescue => x
false
end
def download!(source_url, destination_file)
require 'uri'
require 'net/ssh'
require 'net/scp'
uri = URI(source_url)
Net::SSH.start(uri.host, uri.user) do |ssh|
ssh.scp.download!(uri.path, destination_file) do |ch, name, sent, total|
@ui.clear_line
@ui.report_progress(sent, total)
end
end
@ui.clear_line
end
end
end
module Action
module Box
Download.class_eval do
def initialize(app, env)
@app = app
@env = env
@env["download.classes"] ||= []
@env["download.classes"] += [Downloaders::SSH, Downloaders::HTTP, Downloaders::File]
@downloader = nil
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment