简体   繁体   English

如何从Amazon S3下载上个月创建的文件夹中的所有文件?

[英]How can I download all files from Amazon S3 that are in a folder that was created last month?

How can I download a folder from Amazon S3 that was created last month until the present? 如何从上个月创建的Amazon S3下载一个文件夹,直到现在?

I have this code using boto: 我有使用boto的代码:

for key in bucket.list():
   if last_month < dateutil.parser(key.last_modified).month:
      key.get_contents_to_filename(local_path + key.name)

The problem is the loop will take a long time because it's comparing each file in the folder. 问题是循环将花费很长时间,因为它正在比较文件夹中的每个文件。 I only want to compare the folder timestamp. 我只想比较文件夹时间戳。

If there's a way using the AWS CLI much better. 如果有一种更好地使用AWS CLI的方法。

This is not possible. 这是不可能的。

Amazon S3 does not use directories. Amazon S3不使用目录。 It is a flat storage structure. 它是一个平面存储结构。

To give the appearance of directories, paths are prepended to the Key (filename) of an Object (file). 为了显示目录的外观, 路径位于对象(文件) 的键 (文件名)之前。

For example, an object called cat.jpg stored in a directory called animals would actually have a Key (filename) of animals/cat.jpg . 例如,存储在名为animals的目录中的名为cat.jpg的对象实际上将具有animals/cat.jpg的键(文件名)。

Since the directories do not exist, there is no way to retrieve properties from a directory. 由于目录不存在,因此无法从目录检索属性。

(BTW, there is a concept of "common prefixes" that can work like directories when referring to multiple files, but it still isn't an actual directory.) (顺便说一句,“通用前缀”的概念在引用多个文件时可以像目录一样工作,但它仍然不是实际目录。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM