raju
raju

Reputation: 6936

download whole folder from S3, using php sdk

I am trying to learn PHP SDK S3.

I am able to transfer whole folder from local to S3 bucket using PHP.

Is it possible to copy whole folder from S3 bucket to local, using PHP, if yes then please guide me.

I am unable to do so.

Upvotes: 1

Views: 1747

Answers (2)

Keshu Odedara
Keshu Odedara

Reputation: 21

function aws_download_folder ($bucket,$directory,$localpath)
{
    global $s3Client;    
    $s3Client->downloadBucket($localpath . $directory, $bucket, $directory);
}

//Call Your Function..
aws_download_folder('backup-tanna-accounts','FolderName/','LocalPath');

==> downloadBucket() Is fnuction provided by AWS.
==> $s3Client is your s3 object

Upvotes: 1

Marcelo Agimóvel
Marcelo Agimóvel

Reputation: 1719

Acording with this answer:

There is also an even easier way to do this with the AWS SDK for PHP using the downloadBucket() method. Here's an example (assuming $client is an instance of the S3 client):

$bucket = 'YOUR_BUCKET_NAME'; $directory = 'YOUR_FOLDER_OR_KEY_PREFIX_IN_S3'; $basePath = 'YOUR_LOCAL_PATH/';

$client->downloadBucket($basePath . $directory, $bucket, $directory); The cool thing about this method is that it queues up only the files that don't already exist (or haven't been modified) in the local directory, and attempts to download them in parallel, in order speed up the overall download time. There is a 4th argument to the method (see the link) that includes other options like setting how many parallel downloads you want to happen at a time.

Upvotes: 0

Related Questions