I want to download all files from S3 bucket which are in this path All Buckets /abc/or/uploads
I tried with this snippet but only managed to get files in All Buckets /abc
Changing the path in bucket_list = bucket.list('or/uploads')
this line is not working? 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. It is a flat file structure. To maintain the appearance of directories, path names are stored as part of the object 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")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.