Help us understand the problem. What is going on with this article?

boto で S3 アップローダー

More than 5 years have passed since last update.

Googleで調べればさんざん出てくるわけではあるが。
boto でAWSにファイルアップロードするよ。

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] は実行スクリプト名なのでスキップ
args.pop(0)

for arg in args:
    upload_file = arg

    key     = Key(bucket)
    key.key = upload_file
    key.set_contents_from_filename(upload_file)

    # web 公開モードにする
    key.make_public()
    print "upload file:", key

実行は、アップしたいルートディレクトリから

$ python path/to/upload.py file1 file2 ...

ファイルのパーミッションとか、オプションの制御はマニュアルを参照すればいいと思うよ。

最終的には rsync 的な同期スクリプトにしたいけど、とりあえずの下書きってぇ事で。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away