我注意到似乎没有从AWS管理控制台下载整个s3桶的选项。

有什么简单的方法可以把所有东西都装进我的桶里吗?我正在考虑使根文件夹公共,使用wget抓取它,然后再次使它私有,但我不知道是否有更简单的方法。


当前回答

使用boto3下载具有特定前缀的桶中的所有对象

import boto3

s3 = boto3.client('s3', region_name='us-east-1', 
                     aws_access_key_id=AWS_KEY_ID, 
                     aws_secret_access_key=AWS_SECRET)

def get_all_s3_keys(bucket,prefix):
    keys = []

    kwargs = {'Bucket': bucket,Prefix=prefix}
    while True:
        resp = s3.list_objects_v2(**kwargs)
        for obj in resp['Contents']:
             keys.append(obj['Key'])

        try:
            kwargs['ContinuationToken'] = resp['NextContinuationToken']
        except KeyError:
            break

        return keys

def download_file(file_name, bucket,key):
    file=s3.download_file(
    Filename=file_name,
    Bucket=bucket,
    Key=key)
    return file

bucket="gid-folder"
prefix="test_"
keys=get_all_s3_keys(bucket,prefix):

for key in keys:
     download_file(key, bucket,key)
   
 

其他回答

AWS SDK API是将整个文件夹和存储库上传到AWS S3以及在本地下载整个AWS S3存储桶的最佳选择。

上传整个文件夹到AWS S3: AWS S3 sync。s3: / / BucketName

本地下载整个AWS S3桶:AWS S3 sync S3://BucketName。

您还可以为AWS S3桶中的特定文件夹分配路径,如BucketName/ path。

如果您只想从AWS下载桶,请首先在您的计算机中安装AWS CLI。在终端更改目录到你想下载的文件,并运行这个命令。

aws s3 sync s3://bucket-name .

如果你也想同步本地和s3目录(如果你在本地文件夹中添加了一些文件),运行这个命令:

aws s3 sync . s3://bucket-name

如果您使用带有S3Fox的Firefox,它确实允许您选择所有文件(shift-选择第一个和最后一个),然后右键单击并下载所有文件。

我已经处理了500多个文件,没有任何问题。

您有许多选项可以做到这一点,但最好的是使用AWS CLI。

下面是一篇简介:

Download and install AWS CLI in your machine: Install the AWS CLI using the MSI Installer (Windows). Install the AWS CLI using the Bundled Installer for Linux, OS X, or Unix. Configure AWS CLI: Make sure you input valid access and secret keys, which you received when you created the account. Sync the S3 bucket using: aws s3 sync s3://yourbucket /local/path In the above command, replace the following fields: yourbucket >> your S3 bucket that you want to download. /local/path >> path in your local system where you want to download all the files.

除了关于aws s3同步的建议外,我还建议查看s5cmd。

根据我的经验,我发现对于多次下载或大规模下载,这比AWS CLI要快得多。

S5cmd支持通配符,这样可以工作:

S5cmd cp s3://桶名/* ./文件夹