title: Copying file across Azure container without using azcopy
body: <p>I would like to Copy a file across Azure containers without using azcopy utility.
  Please help with the script(Spring boot or .net example).</p>
  <p>I was able to upload\download file from\to local from\to container.
  Now wondering, how I could achieve remote to remote copy.</p>
  <p>Following code is working fine. All I need now is remote copy.</p>
  <pre><code>using Azure.Storage.Blobs;
  using Azure.Storage.Blobs.Models;
  using Microsoft.Azure.Storage.Blob;
  using System;
  using System.IO;
  using System.Threading.Tasks;
  
  namespace whizlabblob
  {
      class Program
      {
          static string storageconnstring = &quot;DefaultEndpointsProtocol=https;AccountName=mainices;AccountKey=********************&quot;;
          static string containerName = &quot;demo&quot;;
          static string filename = &quot;sample.txt&quot;;
          static string filepath=&quot;C:\\Work\\sample.txt&quot;;
          static string downloadpath = &quot;C:\\Work\\sample2.txt&quot;;
          static async Task Main(string[] args)
          {
              //Container().Wait();
              //CreateBlob().Wait();
              //GetBlobs().Wait();
              // GetBlob().Wait();
              Console.WriteLine(&quot;Complete&quot;);
              Console.ReadKey();
          }
  
          static async Task Container()
          {
           
              BlobServiceClient blobServiceClient = new BlobServiceClient(storageconnstring);
           
              BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
          }
  
  
  
          static async Task CreateBlob()
          {
              
              BlobServiceClient blobServiceClient = new BlobServiceClient(storageconnstring);
              
              BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
              
              BlobClient blobClient = containerClient.GetBlobClient(filename);            
              using FileStream uploadFileStream = File.OpenRead(filepath);
              
  
              await blobClient.UploadAsync(uploadFileStream, true);
              uploadFileStream.Close();
          }
  
  
          static async Task GetBlobs()
          {
              
              BlobServiceClient blobServiceClient = new BlobServiceClient(storageconnstring);
              
              BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
              
              
              await foreach (BlobItem blobItem in containerClient.GetBlobsAsync())
              {
                  Console.WriteLine(&quot;\t&quot; + blobItem.Name);
              }
  
          }
  
          static async Task GetBlob()
          {
              
              BlobServiceClient blobServiceClient = new BlobServiceClient(storageconnstring);
              
              BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
              
              BlobClient blob = containerClient.GetBlobClient(filename);
              
              BlobDownloadInfo blobdata = await blob.DownloadAsync();
  
              
              using (FileStream downloadFileStream = File.OpenWrite(downloadpath))
              {
                  await blobdata.Content.CopyToAsync(downloadFileStream);
                  downloadFileStream.Close();
              }
  
  
              // Read the new file
              using (FileStream downloadFileStream = File.OpenRead(downloadpath))
              {
                  using var strreader = new StreamReader(downloadFileStream);
                  string line;
                  while ((line = strreader.ReadLine()) != null)
                  {
                      Console.WriteLine(line);
                  }
              }
  
          }
      }
  }
  </code></pre>