+-
如何使用boto在两个Amazon S3存储桶之间移动文件?
我必须使用 Python Boto API在一个存储桶之间移动文件. (我需要它从第一个Bucket中“剪切”文件并在第二个Bucket中“粘贴”它.
最好的方法是什么?

**注意:如果我有两个不同的ACCESS KEYS和SECRET KEYS,那有关系吗?

最佳答案
我认为boto S3文档可以回答你的问题.

https://github.com/boto/boto/blob/develop/docs/source/s3_tut.rst

通过boto将文件从一个存储桶移动到另一个存储桶实际上是从源到目标的密钥副本,而不是从源中删除密钥.

您可以访问存储桶:

import boto

c = boto.connect_s3()
src = c.get_bucket('my_source_bucket')
dst = c.get_bucket('my_destination_bucket')

并迭代键:

for k in src.list():
    # copy stuff to your destination here
    dst.copy_key(k.key.name, src.name, k.key.name)
    # then delete the source key
    k.delete()

另见:Is it possible to copy all files from one S3 bucket to another with s3cmd?

点击查看更多相关文章

转载注明原文:如何使用boto在两个Amazon S3存储桶之间移动文件? - 乐贴网