Python 使用boto从S3 bitbucket递归下载特定文件夹及其所有文件
我知道如何使用aws cli递归下载文件Python 使用boto从S3 bitbucket递归下载特定文件夹及其所有文件,python,amazon-web-services,amazon-s3,boto,boto3,Python,Amazon Web Services,Amazon S3,Boto,Boto3,我知道如何使用aws cli递归下载文件 aws s3 cp {s3Directory} {localDirectory} --recursive 但我想使用Python Boto,下面是我的代码。我想从bucket“news live”下载文件夹及其所有文件(“Daily/2017/02/15/”)。当我执行下面的命令时,会创建所有文件夹,但没有下载任何文件 def main(): DOWNLOAD_LOCATION_PATH = "/Users/test/" BUCKET_NAME = '
aws s3 cp {s3Directory} {localDirectory} --recursive
但我想使用Python Boto,下面是我的代码。我想从bucket“news live”下载文件夹及其所有文件(“Daily/2017/02/15/”)。当我执行下面的命令时,会创建所有文件夹,但没有下载任何文件
def main():
DOWNLOAD_LOCATION_PATH = "/Users/test/"
BUCKET_NAME = 'news-live'
conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_ACCESS_SECRET_KEY)
bucket = conn.get_bucket(BUCKET_NAME)
#goto through the list of files
bucket_list = bucket.list('Daily/2017/02/15/')
for l in bucket_list:
key_string = str(l.key)
print("bucket key", l.key)
s3_path = DOWNLOAD_LOCATION_PATH + key_string
try:
print ("Current File is ", s3_path)
l.get_contents_to_filename(s3_path)
except (OSError,S3ResponseError) as e:
pass
# check if the file has been downloaded locally
if not os.path.exists(s3_path):
try:
os.makedirs(s3_path)
except OSError as exc:
# let guard againts race conditions
import errno
if exc.errno != errno.EEXIST:
raise
我不知道如何得到这份工作。类似的问题已经被问过很多次了。检查如何使用boto3执行此问题的答案。你可以在这里找到答案: