WhiskerBiscuit
WhiskerBiscuit

Reputation: 5157

How do I copy files from S3 using powershell?

I have the following script which will copy all files from c:\images to mybucket\myfolder

How do I do the reverse and copy from mybucket\myfolder to c:\images?

$key = "mykey"
$secret = "mysecret"


$cbsnap = "CloudBerryLab.Explorer.PSSnapIn"
if ( (Get-PSSnapin -Name $cbsnap -ErrorAction SilentlyContinue) -eq $null )
{
    Add-PsSnapin $cbsnap
}

Set-CloudOption -PermissionsInheritance "inheritall"

$s3 = Get-CloudS3Connection -Key $key -Secret $secret

Set-Logging –LogPath c:\temp\sync.log -LogLevel info

$bucket = "mybucket\myfolder"
$local = "c:\images\"

#copy from local to S3
$s3selflhost = $s3 | Select-CloudFolder -path $bucket
$src = Get-CloudFilesystemConnection | Select-CloudFolder -path $local
$src | Copy-CloudItem $s3selflhost -filter "*"

Upvotes: 1

Views: 2901

Answers (1)

mistika
mistika

Reputation: 2471

Just switch parameters that represent folders on S3 and local disk:

$s3selflhost | Copy-CloudItem $src -filter "*"

In fact this is just a pipelined version of the following command:

Copy-CloudItem -Destination $src -filter "*" -Folder $s3selflhost

So you actually switch destination and source folder parameters.

Upvotes: 1

Related Questions