Skip to content

Instantly share code, notes, and snippets.

@madr
Created June 21, 2012 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save madr/2965201 to your computer and use it in GitHub Desktop.
Save madr/2965201 to your computer and use it in GitHub Desktop.
Upload static file dir recursively to Amazon S3 using python
from os import listdir
from os.path import isdir
from simples3 import S3Bucket # pip install simples3
root = "../static"
exclude = [".DS_Store"]
A = "access key"
B = "secret key"
bucket = "guidenext"
s3 = S3Bucket(bucket,
access_key=A,
secret_key=B,
base_url="http://%s.s3.amazonaws.com" % bucket)
def upload_file(src):
print "- uploading %s" % src
f = open(src)
s3.put(src.replace(root, "admin"), f.read())
def upload_dir(path):
for f in listdir(path):
if f not in exclude:
if isdir("%s/%s" % (path, f)) is True:
upload_dir("%s/%s" % (path, f))
else:
upload_file("%s/%s" % (path, f))
upload_dir(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment