将文件从 Amazon EC2 中的 S3 存储桶下载到 Windows 7 中的本地驱动器



我正在尝试通过 boto3 和 python3 脚本将所有示例文件从 amazon ec2 中的 s3 存储桶下载到我的本地硬盘驱动器。 这是脚本。

#downloading files from s3
import boto3
import sys
import os
import argparse
import threading
from botocore.client import Config
instance_id = "i-03e7f6391a0f523ee"
action = 'ON'
ec2 = boto3.client('ec2')
s3=boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)
my_bucket=s3.Bucket('tkbucket32')
print("listing all files in bucket")
for s3_file in my_bucket.objects.all():
print(s3_file.key)
s3.meta.client.download_file('tkbucket32', 'hello.txt', '/tmp/hello.txt')

目前存储桶中有以下文件

您好.txt我的主页.html

现在我希望将它们下载到

D:folder1folder2folder3

我在 Windows 7 中运行脚本。 我的问题是这条线

s3.meta.client.download_file('tkbucket32', 'hello.txt', '/tmp/hello.txt')

我在哪里指定要下载这些文件的本地硬盘驱动器的路径?

更改此行:

s3.meta.client.download_file('tkbucket32', 'hello.txt', '/tmp/hello.txt')

自:

s3.meta.client.download_file('tkbucket32', 'hello.txt', 'D:\folder1\folder2\folder3\hello.txt')

最新更新