Skip to content

Instantly share code, notes, and snippets.

@mndoci
Forked from cdollins/gist:91288
Created April 7, 2009 15:45
Show Gist options
  • Save mndoci/91302 to your computer and use it in GitHub Desktop.
Save mndoci/91302 to your computer and use it in GitHub Desktop.
# This is a simple command line tool for uploading
# and folders of files to AWS S3. You must first
# create a vaild bucket to upload to.
#!/usr/bin/env ruby
require 'rubygems'
require 'pathname'
require 'aws/s3'
include AWS::S3
if ARGV.size < 2
p "Usage: s3cli.rb bucket file ..."
exit
end
Base.establish_connection!(
:access_key_id => 'public',
:secret_access_key => 'private'
)
bucket = ARGV.shift
begin
Bucket.find(bucket)
rescue ResponseError => error
p error.message
exit 0
end
ARGV.each do |name|
file = Pathname.new(name)
if file.file?
S3Object.store(file.basename.to_s, file.open, bucket)
elsif file.directory?
ARGV.concat file.children
else
p "#{file} does not exist"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment