Craig Gallagher
Craig Gallagher

Reputation: 1633

Copying Files Using AzCopy C#

I'm having an issue when copying blob containers from one storage account to another using AzCopy.

When trying to start the process I get this error Error:

Any idea why I'm having this issue?

    unknown command "/Source:https://pslfilestore.blob.core.windows.net/downloads" for "azcopy"
    Run 'azcopy --help' for usage.
    System.IO.StreamWriterdownloads
    unknown command "/Source:https://pslfilestore.blob.core.windows.net/downloads" for "azcopy

"

Please see code below

foreach (CloudBlobContainer items in containers)
  { 
    var AzCopyProcess = new Process();
    AzCopyProcess.StartInfo.UseShellExecute = false;
    AzCopyProcess.StartInfo.RedirectStandardOutput = true;
    AzCopyProcess.StartInfo.FileName = strCommand;
    //pass storage account name, container and the key                           
    AzCopyProcess.StartInfo.Arguments = $"/Source:https://{storageAccountName}.blob.core.windows.net/{items.Name} /Dest:{dayBlob.Uri}/{storageAccountName}/{items.Name} /SourceKey:{accountKey.ToString()} /DestKey:{pslFileStoreBackUpKey.ToString()} /S";


     AzCopyProcess.Start();

       StreamWriter stdOut = new StreamWriter(Console.OpenStandardOutput());
       stdOut.AutoFlush = true;
       Console.Write(stdOut);
       var output = AzCopyProcess.StandardOutput.ReadToEnd();
       Console.WriteLine($"{items.Name} {output}");
}

Upvotes: 0

Views: 4101

Answers (1)

George Chen
George Chen

Reputation: 14344

From your error report, you are using the AzCopy V10 however your code is in V8 format. I think this is the problem.

In V10 the copy usage should be: azcopy copy [source] [destination] [flags].

And the copy container syntax should be: azcopy cp "https://<source-storage-account-name>.blob.core.windows.net/<container-name>" "https://<destination-storage-account-name>.blob.core.windows.net/<container-name>" --recursive.

For more details you could refer to this doc: Transfer data with AzCopy and Blob storage. Or you could use like azure cp --help to get the details.

Upvotes: 2

Related Questions