Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write-S3Object : The file indicated by the FilePath property does not exist

I am writing a powershell script that will upload the filenames listed in a text file that was created by a robocopy script to an S3 bucket and I cannot seem to get the syntax write for the Write-S3Object command.

Here is my code and I'm hoping you can help me debug it:

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
    }
}

For whatever reason $file isn't loading properly though it displays just fine in write-output. What gives?

All of the replace commands are used to make the robocopy output:

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

to S3 format:

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

like image 826
Agrikk Avatar asked Nov 07 '25 01:11

Agrikk


1 Answers

Write-S3Object doesn't understand the s3:// syntax. Simply give it the bucket name (to the -BucketName parameter) and the local filename to the -File parameter. If you don't supply a value for -Key the filename will be used.

like image 187
Steve Roberts Avatar answered Nov 09 '25 09:11

Steve Roberts