Skip to content

Instantly share code, notes, and snippets.

@gabrielengel
Created April 17, 2012 19:13
Show Gist options
  • Save gabrielengel/2408360 to your computer and use it in GitHub Desktop.
Save gabrielengel/2408360 to your computer and use it in GitHub Desktop.
Upload folders into Rackspace Cloudfiles
# 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