If you look it up on Google, it will come out a lot. I'll upload the file to AWS with boto.
upload.py
#!/usr/bin/python
# coding: utf8
import sys
from boto.s3.connection import S3Connection
from boto.s3.key import Key
AWS_ACCESS_KEY = 'XXXXXXX'
AWS_SECRET_KEY = 'YYYYYYY'
BUCKET_NAME = 'mybucket'
conn = S3Connection(
aws_access_key_id = AWS_ACCESS_KEY,
aws_secret_access_key = AWS_SECRET_KEY)
bucket = conn.get_bucket(BUCKET_NAME)
print "connect:", bucket
if len(sys.argv) == 1:
print "Error: no input file specified"
sys.exit()
args = sys.argv
# arg[0]Is the execution script name, so skip it
args.pop(0)
for arg in args:
upload_file = arg
key = Key(bucket)
key.key = upload_file
key.set_contents_from_filename(upload_file)
#Put into web public mode
key.make_public()
print "upload file:", key
Execution is from the root directory you want to upload
$ python path/to/upload.py file1 file2 ...
You can refer to the Manual for file permissions and option control.
In the end, I want to make it a rsync-like synchronization script, but for the time being, I'll draft it.
Recommended Posts