使用 boto python 从 s3 递归下载文件. [英] Downloading the files from s3 recursively using boto python.
本文介绍了使用 boto python 从 s3 递归下载文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 s3 中有一个存储桶,它有很深的目录结构.我希望我可以一次下载它们.我的文件看起来像这样:
I have a bucket in s3, which has deep directory structure. I wish I could download them all at once. My files look like this :
foo/bar/1. .
foo/bar/100 . .
有什么方法可以使用python中的boto lib从s3存储桶中递归下载这些文件?
Are there any ways to download these files recursively from the s3 bucket using boto lib in python?
提前致谢.
推荐答案
您可以像这样下载存储桶中的所有文件(未经测试):
You can download all files in a bucket like this (untested):
from boto.s3.connection import S3Connection
conn = S3Connection('your-access-key','your-secret-key')
bucket = conn.get_bucket('bucket')
for key in bucket.list():
try:
res = key.get_contents_to_filename(key.name)
except:
logging.info(key.name+":"+"FAILED")
请记住,S3 中的文件夹只是编写密钥名称的另一种方式,只有客户端才会将其显示为文件夹.
Keep in mind that folders in S3 are simply another way of writing the key name and only clients will show this as folders.
这篇关于使用 boto python 从 s3 递归下载文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文