import software.amazon.awssdk.transfer.s3.S3TransferManager; import software.amazon.awssdk.transfer.s3.model.DownloadDirectoryRequest; import software.amazon.awssdk.transfer.s3.model.CompletedDirectoryDownload; import java.nio.file.Paths; public void downloadFolder(String bucketName, String s3Prefix, String localPath) { S3TransferManager transferManager = S3TransferManager.create(); DownloadDirectoryRequest downloadDirectoryRequest = DownloadDirectoryRequest.builder() .destinationDirectory(Paths.get(localPath)) .bucket(bucketName) .prefix(s3Prefix) .build(); CompletedDirectoryDownload completedDirectoryDownload = transferManager .downloadDirectory(downloadDirectoryRequest) .completionFuture() .join(); // Wait for completion // Handle any failed transfers completedDirectoryDownload.failedTransfers().forEach(fail -> System.out.println("Failed to download: " + fail.exception().getMessage())); } Use code with caution.
If you need to download a specific list of keys that aren't in the same virtual directory, you can use the standard S3 client in a loop or with parallel streams. Sequential vs. Parallel Downloads download multiple files from s3 java
: Handles recursive subdirectories automatically. import software
How to Download Multiple Files from S3 in Java Downloading multiple files from Amazon S3 in Java is a common task that can range from a simple loop of individual downloads to high-performance parallel transfers using the . This guide covers the most efficient methods using the AWS SDK for Java 2.x . 1. Using the S3 Transfer Manager (Recommended) Manual Batch Downloads (Low-Level)
The is a high-level utility that simplifies downloading entire directories or lists of files. It is built on top of the asynchronous S3 client and can automatically parallelize transfers for better performance. Downloading an Entire Directory
To download all files with a specific prefix (essentially a "folder") into a local directory, use the downloadDirectory method.
: You can track progress in real-time or pause/resume transfers. 2. Manual Batch Downloads (Low-Level)