1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHPでAWS S3からディレクトリ単位でダウンロード

Last updated at Posted at 2021-02-25

前提条件

AWS SDK for PHP 3.x を利用

やってみた感想

CommandPool利用のために配列を作成する必要がなく
コードもシンプルになるのでよい

AWS S3 バケットを再帰的にダウンロード

同期転送

sample.php
<?php

use Aws\S3\S3Client;
use Aws\S3\Transfer;

$client = new S3Client([
    'region'  => '****',
    'version' => 'latest',
]);

// from
$source = 's3://bucket/foo';
// to ローカルディレクトリのパス
$dest   = '/path/to/destination/dir';

$manager = new Transfer(
    $client,
    $source,
    $dest,
);
$manager->transfer();

非同期転送

sample.php
<?php

use Aws\S3\S3Client;
use Aws\S3\Transfer;

$client = new S3Client([
    'region'  => '****',
    'version' => 'latest',
]);

// from
$source = 's3://bucket/foo';
// to ローカルディレクトリのパス
$dest   = '/path/to/destination/dir';

$manager = new Transfer(
    $client,
    $source,
    $dest,
);

$promise = $manager->promise();
$promise
    ->then(function () {
        echo 'Done!';
    })
    ->otherwise(function ($reason) {
        echo 'Transfer failed';
    });

参考

Amazon S3バージョン 3 での AWS SDK for PHP Transfer Manager

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?