download files from s3 bucket using C#

 

For enable CLI Command, kindly Download the below msi file and install it.

Download .msi to enable CLI command

CLI COMMAND

C:\> aws s3 cp "s3://myFolers3bucket/FILE" . --recursive
C# code to download files from S3 bucket.
string accessKey = "abc123353";
string secretKey = "secret1233534";
string bucketName = "myFolers3bucket"
TransferUtility fileTransferUtility =   new TransferUtility(new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.USEast2));


BasicAWSCredentials basicCredentials = new BasicAWSCredentials(accessKey,secretKey);
AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey), Amazon.RegionEndpoint.USEast2);
ListObjectsRequest request = new ListObjectsRequest();

ListObjectsResponse response = s3Client.ListObjects(request.BucketName= bucketName, request.Prefix="FILE/");

foreach (S3Object obj in response.S3Objects)
{
    try
    {
        Console.WriteLine("{0}", obj.Key);
        fileTransferUtility.Download(@"C:\DownloadTemp", bucketName, obj.Key);

    }
    catch (Exception Excep)
    {
        Console.WriteLine(Excep.Message, Excep.InnerException);
    }
}  
DOT NET ADDA

interested in solving the problems based on technologies like Amazon AWS ,Google Cloud, Azure and Dot related technology like asp.net, C#, asp.net core API, swagger, react js,Jquery ,javascripts, bootstrap, css,html, ms sql,IIS,WPF ,WCF,Firebase,RDLC Report etc..

إرسال تعليق (0)
أحدث أقدم