amazon-web-services - 写入 S3Object : The file indicated by the FilePath property does not exist

标签 amazon-web-services powershell amazon-s3

我正在编写一个 powershell 脚本,它将由 robocopy 脚本创建的文本文件中列出的文件名上传到 S3 存储桶,但我似乎无法获得 Write-S3Object 命令的语法写入。

这是我的代码,我希望你能帮我调试它:

foreach($line in Get-Content C:\Scripts\ToS3\FileList1.txt) {
    if($line -match $regex){
        $key = $line -replace [regex]::Escape('\\server\e$\'), '/' -replace 
"c:\\", "s3://mybucket/" -replace "\\","/" -replace "  `t","" -replace "`t",""
        $file = $line  -replace "  `t","" -replace "`t",""
        write-output `"$file`"
        write-output `"$key`"
        Write-S3Object -BucketName mybucket -File `"$file`" -Key `"$key`" -ProfileName xxxx
    }
}

无论出于何种原因 $file 都没有正确加载,尽管它在写入输出中显示得很好。给了什么?

所有替换命令都用于生成 robocopy 输出:

\server\e$\Data\example folder 1\example folder 2\another file 2.txt

到S3格式:

s3://mybucket/Data/example folder 1/example folder 2/another file 2.txt

最佳答案

Write-S3Object 不理解 s3://语法。只需将存储桶名称(给 -BucketName 参数)和本地文件名给 -File 参数即可。如果您不为 -Key 提供值,将使用文件名。

关于amazon-web-services - 写入 S3Object : The file indicated by the FilePath property does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53093709/

相关文章:

amazon-web-services - 负载均衡器后面的 HTTPS->HTTP 是否被认为是安全的?

amazon-web-services - Dockerrun aws 硬编码内存

amazon-web-services - 由CloudWatch事件触发时AWS Lambda重试行为

powershell - 如何从主 Windows PowerShell 脚本将参数传递给 sqlps

amazon-s3 - 如何引用Cloud Formation中创建的S3存储桶

hadoop - 亚马逊弹性 map 减少 : Listing job flows in command line tools Issue?

regex - 获取模式的最后一个实例

powershell - Powershell对合规性搜索执行操作

ruby-on-rails - 通过回形针向 S3 提供 Content-MD5 header

php - AWS EC2实例创建数据库并上传页面