Created
April 17, 2012 19:13
-
-
Save gabrielengel/2408360 to your computer and use it in GitHub Desktop.
Upload folders into Rackspace Cloudfiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding : utf-8 | |
# | |
# Author: Gabriel Engel | |
# Based on: https://github.com/rackspace/cloudfiles | |
# | |
require 'rubygems' | |
require 'cloudfiles' | |
# Configure Here | |
USERNAME = "" | |
API_KEY = "" | |
CONTAINER = "" | |
FOLDER = "" # This folder contents will be uploaded | |
# That's all. Only mess bellow if you want to | |
# do something diferent than uploading a folder | |
# == == == == == == == == == == == == == | |
# Log into the Cloud Files system | |
BASE = `pwd`.chop | |
cf = CloudFiles::Connection.new(:username => USERNAME, :api_key => API_KEY) | |
container = cf.container(CONTAINER) | |
files = `find #{FOLDER}` | |
files = files.split("\n").map{|n| n.gsub("#{FOLDER}/", '').to_s } | |
puts ("="*40) + " \n Starting to upload #{files.size} files \n" + ("="*40) | |
files.each_with_index do |file, i| | |
file_path = "#{BASE}/#{FOLDER}/#{file}" | |
if File.exists?(file_path) | |
if File.directory?(file_path) | |
puts "\n" + ("="*20) + " Directory #{file_path} " + ("="*20) | |
else | |
puts "Uploading #{file} (#{i}/#{files.size})" | |
puts " = Source: #{file_path}" | |
object = container.create_object( file, false) | |
object.write File.open(file_path) | |
end | |
else | |
puts "Missing file: #{file_path}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment