上载的特定类型的所有文件至S3与Powershell的 [英] uploading all files of a specific type to S3 with Powershell

查看:289
本文介绍了上载的特定类型的所有文件至S3与Powershell的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做:

foreach ($f in (Get-ChildItem -filter "*.flv")){
    Write-S3Object -BucketName bucket.example -File $f.fullName -Key $f.name -CannedACLName PublicRead
}

我得到这个错误:

I get this error:

Write-S3Object :
At line:1 char:51
+  foreach ($f in (Get-ChildItem -filter "*.flv")){ Write-S3Object -BucketName xx. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Objec
   t], InvalidOperationException
    + FullyQualifiedErrorId : Amazon.S3.AmazonS3Exception,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet

我是什么做错了吗?有什么我可以做多看错误的,或者这只是一个语法的问题?

What am I doing wrong? Is there anything I can do to see more of the error, or is this just a syntax issue?

我怎样才能否则一切一定的文件类型使用PowerShell的上传到一个桶?

How can I otherwise upload all of a certain filetype to a bucket using powershell?

我故意设置设置DefaultAWSRegion 到水桶不在,并得到了区域

I intentionally set Set-DefaultAWSRegion to a region that the bucket wasn't in, and got

Write-S3Object : The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. 

为错误消息,如预期的,所以它看起来像它可以连接到桶和它知道它不是在一个特定区域。

as an error message, as expected, so it looks like it can connect to the bucket and it knows that it isn't in a certain region.

另外,如果我进入 S3:// preFIX斗名之前,我得到了水桶无法找到的消息,所以它它看起来像我进入现在什么是正确的。

Also, if I enter the s3:// prefix before the bucket name, I get a message that the bucket couldn't be found, so it it looks like what I'm entering now is correct.

我可以做得到,S3Bucket和看到所有在我的账户桶,所以我知道,它的配置正确。

I can do Get-S3Bucket and see all of the buckets on my account, so I know that it's configured correctly.

如果我做的:

> $f = Get-ChildItem -filter "*.flv"
> Write-S3Object

cmdlet Write-S3Object at command pipeline position 1
Supply values for the following parameters:
BucketName: bucket.name
Key: $f[0].name
File: $f[0].fullName
Write-S3Object : The file indicated by the FilePath property does not exist!
At line:1 char:1
+ Write-S3Object
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Amazon.PowerShe...eS3ObjectCmdlet:WriteS3ObjectCmdlet) [Write-S3Objec
   t], InvalidOperationException
    + FullyQualifiedErrorId : System.ArgumentException,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet

如果我这样做 $ F [0] .fullName 分开,我得到的完整路径目标。 然而,这种有空格。难道这是一个问题吗?

If I do $f[0].fullName seperately, I get the full path to the object. However, this has spaces in it. Could this be a problem?

推荐答案

当你缺少这样的命令行参数填充,你需要指定自己的文本字符串值。当我在本地模仿您的问题:

When you fill in missing parameters like that from the command line, you need to specify their literal string values. When I mimicked your issue locally:

PS C:\> Write-S3Object

cmdlet Write-S3Object at command pipeline position 1
Supply values for the following parameters:
BucketName: MyTestBucketNameHere
Key: $testName
File: C:/test.txt

我结束了在S3上的文件,其关键被命名为 $测试名,因为变量在这种情况下不进行评估。同样的,你得到这个的的文件路径属性指定的文件不存在!的错误,因为在你的文件系统命名为任何文件 $ F [0] .fullName

I ended up with a file on S3 whose key was named $testName, because variables aren't evaluated in that context. Likewise, you're getting this "The file indicated by the FilePath property does not exist!" error because there is no file in your filesystem named $f[0].fullName.

这是例子写一个文件到S3:

An example to write a single file to S3:

PS C:> Write-S3Object -BucketName "MyTestBucketName" -Key "file.txt" -File "C:/test.txt"

要写入的所有文件,以S3:

To write all of your files to S3:

PS C:\> (Get-ChildItem -filter "*.flv") | % { Write-S3Object -BucketName "MyTestBucketName" -File $_ -Key $_.name}

这将首先获得在当前目录中的FLV文件类型的所有文件,并为每个对象(再由百分号psented $ P $),我们将写入文件(重新按<$ C psented $ P $ $ C> $ _ )以MyTestBucketName用钥匙就是当前文件正在迭代的name属性。

This will first get all files with the flv file-type in your current directory, and for each object (represented by the percent sign) we will write the file (represented by $_) to MyTestBucketName with a Key that is the name property of the current file being iterated.

这篇关于上载的特定类型的所有文件至S3与Powershell的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆