当前位置:  开发笔记 > 编程语言 > 正文

如何将文件从s3服务下载到本地文件夹

如何解决《如何将文件从s3服务下载到本地文件夹》经验,为你挑选了1个好方法。

我要求将文件从简单存储服务下载到本地文件夹,并计算本地文件夹中的no.of文件并检查简单存储服务,然后发送包含文件数量的邮件.

我试图从简单的存储服务下载文件,但我收到的错误就像get-s3object commandnotfoundexception.我该如何解决这个问题?

代码参考我已经采取

# Your account access key - must have read access to your S3 Bucket
$accessKey = "YOUR-ACCESS-KEY"
# Your account secret access key
$secretKey = "YOUR-SECRET-KEY"
# The region associated with your bucket e.g. eu-west-1, us-east-1 etc. (see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions)
$region = "eu-west-1"
# The name of your S3 Bucket
$bucket = "my-test-bucket"
# The folder in your bucket to copy, including trailing slash. Leave blank to copy the entire bucket
$keyPrefix = "my-folder/"
# The local file path where files should be copied
$localPath = "C:\s3-downloads\"    

$objects = Get-S3Object -BucketName $bucket -KeyPrefix $keyPrefix -AccessKey $accessKey -SecretKey $secretKey -Region $region

foreach($object in $objects) {
    $localFileName = $object.Key -replace $keyPrefix, ''
    if ($localFileName -ne '') {
        $localFilePath = Join-Path $localPath $localFileName
        Copy-S3Object -BucketName $bucket -Key $object.Key -LocalFile $localFilePath -AccessKey $accessKey -SecretKey $secretKey -Region $region
    }
}

Will.. 9

由于此问题是“ powershell下载s3文件”的Google最高搜索结果之一,因此我将在标题中回答该问题(即使实际问题文本不同):

Read-S3Object -BucketName "my-s3-bucket" -KeyPrefix "path/to/directory" -Folder .

Set-AWSCredentials如果它不是公共存储桶,则可能需要致电。



1> Will..:

由于此问题是“ powershell下载s3文件”的Google最高搜索结果之一,因此我将在标题中回答该问题(即使实际问题文本不同):

Read-S3Object -BucketName "my-s3-bucket" -KeyPrefix "path/to/directory" -Folder .

Set-AWSCredentials如果它不是公共存储桶,则可能需要致电。

推荐阅读
小妖694_807
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有