我是python新手,需要帮助从S3存储桶中存在的特定伪文件夹下载所有文件。下面的代码开始下载存储桶中存在的所有文件。如何实现我的目标。
ontap event
预先感谢
答案 0 :(得分:0)
class Static_file_downloading:
def __init__(self) -> None:
self.client = boto3.client("s3")
self.s3 = boto3.resource("s3")
def getFiles(self):
try:
res = self.client.list_objects(
Bucket="bucket-name",
MaxKeys=5
)
except:
print("No bucket found")
result_set = []
if "Contents" in res:
for result in res["Contents"]:
if result["Size"] > 0:
result_set.append(result)
else:
print("file not found")
for i in range(len(result_set)):
file_name = result_set[i]["Key"]
print(f"downloading {file_name}")
self.s3.meta.client.download_file(
"bucket-name",
file_name,
path_to_download,
)