简体   繁体   English

无法从S3存储桶下载文件

[英]Unable to download files from S3 bucket

I want to download all files from S3 bucket which are in this path All Buckets /abc/or/uploads 我想从S3存储桶中下载所有存储桶中的所有文件All Buckets /abc/or/uploads

I tried with this snippet but only managed to get files in All Buckets /abc 我尝试使用此代码片段,但只设法获取All Buckets /abc文件

Changing the path in bucket_list = bucket.list('or/uploads') this line is not working? 更改bucket_list = bucket.list('or/uploads')的路径此行不起作用? why? 为什么?

import boto
import sys, os
import logging

bucket_name = 'abc'
conn = boto.connect_s3('XXXXXXXXXXXXXX', 'XXXXXXXXXXXXXXXXX+XXXXXXXXXXXXXX')
bucket = conn.get_bucket(bucket_name)
bucket_list = bucket.list('or/uploads')

for key in bucket.list():
    try:
        res = key.get_contents_to_filename(key.name)
        print "done"
    except:
        logging.info(key.name + ":" + "FAILED")

Amazon S3 does not have folders/directories. Amazon S3没有文件夹/目录。 It is a flat file structure. 它是一个平面文件结构。 To maintain the appearance of directories, path names are stored as part of the object Key (filename). 为了保持目录的外观,路径名称存储为对象Key(filename)的一部分。

Make sure the place where you are downloading the files, have exact same structure ie. 确保下载文件的位置具有完全相同的结构,即。 /abc/or/uploads

snippet 片段

for key in bucket.list('or/uploads'):
    try:
        res = key.get_contents_to_filename(key.name)
        print "done"
    except:
        logging.info(key.name + ":" + "FAILED")

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM