How to download directory from AWS S3 bucket in C#?

Download Directory from Amazon S3 

AIM : Download whole directory from AWS S3 bucket using .NET SDK in C#.

TransferUtility  Class :

Provides high level utility for managing transfer to and from Amazon S3 bucket.

TransferUtility provides simple API for uploading and downloading content from Amazon S3. It widely uses  Amazon S3 multipart uploads to achieve enhanced throughput, performance and reliability.

When dealing with large content size and high bandwidth, this can increase throughput significantly.

Inheritance Hierarchy :

           Amazon.S3.Transfer.TransferUtility

Namespace :

     Amazon.S3.Transfer

TransferUtility has so many methods which can use to download directory from Amazon S3 , download single file to the Amazon S3, upload single file or multiple file to the Amazon S3 ,etc.


C# Syntax :

TransferUtility.DownloadDirectory(

            String bucketName,

            String s3Directory,

            String localDirectory

)

TransferUtility.DownloadDirectory(

            TransferUtilityDownloadDirectoryRequest request

)

Example : Downlaod Amazon s3 directory to local folder using C#.

public void DownloadDirectory(string bucketName, string s3Directory, string localDirectory)

{

    try {

        TransferUtilityDownloadDirectoryRequest request = new                                    TransferUtilityDownloadDirectoryRequest()

                {

                    BucketName = bucketName,             // Amazon S3 bucket name

                    S3Directory = s3Directory,           // S3 directory name

                    LocalDirectory = localDirectory,    // Your local directory name 

                };

// awsAccessKeyId : Your AWS bucket Access Key

//awsSecretAccessKey : Your AWS secret access Key

// region : AWS bucket region located in.  

TransferUtility transferUtility  =  new                            TransferUtility(awsAccessKeyId,awsSecretAccessKey,region);

transferUtility.DownloadDirectory(request);

        }

        catch(AmazonS3Exception s3Exception)    {

                Console.WirteLine(s3Exception.Message , s3Exception.InnerException) ;   

        }

        catch(Exception exception)    {

                Console.WriteLine(exception.Message , exception.InnerException);

        }

}


To know more about TransferUtility class and it's methods visit AWS Docs.


-Contribute By :

Parth Sapra

innovativethings5@gmail.com


Comments

Post a Comment