AzCopy.Net is a .net standard library for AzCopy. It is a thin wrapper out of AzCopy v10 cli.
First, add nuget reference to AzCopy.Client. It provides straight forward API to call into AzCopy v10 cli.
<PackageReference Include="AzCopy.Client" Version="1.0.0" />
Then add reference to one of the four nuget asset packages based on your OS and platform. The version of these packages are corresponded to the version of azcopy v10 cli it carries with.
- AzCopy.WinX64
- AzCopy.WinX86
- AzCopy.OsxX64
- AzCopy.LinuxX64
For example:
<PackageReference Include="AzCopy.WinX64" Version="1.0.0" />
If azcopy v10 cli has already installed on your machine, you can also add its full path to $AZCOPYPATH. When running the app, AzCopy.Client will use the azcopy cli pointed by $AZCOPYPATH.
Finally, use AzCopy.Client the same way of using azcopy in cmd!
var localFile = new LocalLocation()
{
UseWildCard = true,
Path = @"src",
};
var sasLocation = new RemoteSasLocation()
{
ResourceUri = @"uri",
Container = @"container"
Path = @"dest",
SasToken = @"sastoken",
};
var option = new AZCopyOption()
{
IncludePattern = "*.jpg;*.png",
};
var client = new AZCopyClient();
// subscribe output event hander to get output from azcopy v10 cli
client.OutputMsgHandler += (object sender, JsonOutputTemplate e) =>
{
Console.WriteLine(e.MessageContent);
};
await client.CopyAsync(localFile, sasLocation, option);
AzCopy.Net supports all commands that azcopy v10 cli has. The interface of supported command is AzCopy.Contract.IAZCopyClient, and is implemented by AzCopy.Client.AzCopyClient class.
The supported command list is presented below.
benchcopydocenvjobs cleanjobs listjobs removejobs resumejobs showlistloginlogoutmakeremovesync
The following scenarios have been validated on windows, mac os and ubuntu.
- Upload files and directories to azure blob container (use SAS only)
- Delete files and directories from azure blob container (use SAS only)
- Download files and directories from azure blob container (use SAS only)
https://pkgs.dev.azure.com/xiaoyuz0315/BigMiao/_packaging/AzCopy.Net/nuget/v3/index.json
| AzCopy.Net | Local |
|---|---|
| AzCopy.Contract | |
| AzCopy.Client | |
| AzCopy.WinX64 | |
| AzCopy.WinX86 | |
| AzCopy.OsxX64 | |
| AzCopy.LinuxX64 |
Check AzCopy.Test for more examples.