C# S3 Bucket TransferUtilityDownloadRequest 工作但 TransferUtilityDownloadDirectoryRequest 不工作

C# S3 Bucket TransferUtilityDownloadRequest working but TransferUtilityDownloadDirectoryRequest does not

我正在使用 TransferUtilityDownload 和 TransferUtilityDownloadDirectory 下载文件和完整目录。但是,即使我使用相同的存储桶名称格式,它也适用于单个文件但不适用于目录和 returns 403 访问被拒绝。 (与列出对象相同的问题):

        string bucketName = "my-bucket-us-east-1-prod";
        string UnscheduledIn = "abc/butter/input_butter_11nov2019/unscheduled";

        AmazonS3Client client = new AmazonS3Client(RegionEndpoint.USEast1);

        // request for object download
        var request = new TransferUtilityDownloadRequest(); 
        // request for directory download
        var drequest = new TransferUtilityDownloadDirectoryRequest();

        //This request for single file download
        request.BucketName = bucketName + "/" + UnscheduledIn;
        request.FilePath = "D:\input\" + "test.csv";
        request.Key = "test.csv";

        //This request for directory download
        drequest.BucketName = bucketName + "/" + UnscheduledIn;
        drequest.S3Directory = "unscheduled"; 
        drequest.LocalDirectory = "D:\input\";
        drequest.DownloadFilesConcurrently = true;

        TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(RegionEndpoint.USEast1));

        // This one works
        fileTransferUtility.Download(request);

        // This one does not work
        fileTransferUtility.DownloadDirectory(drequest); 

403 Access Denied 错误通常是由错误的存储桶或目录名称引起的(如果请求找不到存储桶或目录,这是一个已知问题)。但是存储桶名称和目录名称是正确的。我想知道是否缺少格式或设置某些属性?

快速注意此版本也 returns 相同的 403 错误:

               //This request for directory download
              drequest.BucketName = bucketName;
              drequest.S3Directory = UnscheduledIn; 
              drequest.LocalDirectory = "D:\input\";
              drequest.DownloadFilesConcurrently = true;

似乎存储桶名称和 s3 目录路径存在一些问题。使用这段代码更新您的代码。

//This request for directory download
drequest.BucketName = bucketName;
drequest.S3Directory = '/' + UnscheduledIn; 
drequest.LocalDirectory = "D:\input";
drequest.DownloadFilesConcurrently = true;

更新:

一般情况下,403 forbidden 来自服务器以进行身份​​验证failed/Permission 问题。 请检查您的存储桶策略以允许下载。

    {
      "Sid": "AllowAllS3ActionsInUserFolder",
      "Effect": "Allow",
      "Action": ["s3:*"],
      "Resource": ["arn:aws:s3:::my-bucket-us-east-1-prod/abc/butter/input_butter_11nov2019/*","arn:aws:s3:::my-bucket-us-east-1-prod/abc/butter/input_butter_11nov2019/unscheduled/*"]
    }