Unable to download files from S3 bucket
<p>I want to download all files from S3 bucket which are in this path <code>All Buckets /abc/or/uploads</code></p>

<p>I tried with this snippet but only managed to get files in <code>All Buckets /abc</code></p>

<p>Changing the path in <code>bucket_list = bucket.list('or/uploads')</code>
this line is not working? why?</p>

<pre><code>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")
</code></pre>

<p>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). </p>

<p>Make sure the place where you are downloading the files, have exact same structure i.e..  <code>/abc/or/uploads</code> </p>

<p>snippet </p>

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

<p><a href="https://stackoverflow.com/questions/31918960/boto3-to-download-all-files-from-a-s3-bucket/31929277#31929277">Source</a> </p>

python amazon-web-services amazon-s3