次の方法で共有


Azure Storage Data Movement File Shares client library for .NET - version 12.0.0-beta.3

Server Version: 2020-04-08, 2020-02-10, 2019-12-12, 2019-07-07, and 2020-02-02

Project Status: Beta

This product is in beta. Some features will be missing or have significant bugs. Please see Known Issues for detailed information.


Azure Storage is a Microsoft-managed service providing cloud storage that is highly available, secure, durable, scalable, and redundant. Azure Storage includes Azure Blobs (objects), Azure Data Lake Storage Gen2, Azure Files, and Azure Queues.

The Azure Storage Data Movement library is optimized for uploading, downloading and copying customer data.

The Azure.Storage.DataMovement.Files.Shares library provides infrastructure shared by the other Azure Storage client libraries.

Source code | Package (NuGet) | API reference documentation | REST API documentation | Product documentation

Getting started

Install the package

Install the Azure Storage client library for .NET you'd like to use with NuGet and the Azure.Storage.DataMovement.Files.Shares client library will be included:

dotnet add package Azure.Storage.DataMovement --prerelease
dotnet add package Azure.Storage.DataMovement.Files.Shares --prerelease

Prerequisites

You need an Azure subscription and a Storage Account to use this package.

To create a new Storage Account, you can use the Azure Portal, Azure PowerShell, or the Azure CLI. Here's an example using the Azure CLI:

az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS

Authenticate the client

The Azure.Storage.DataMovement.Files.Shares library uses clients from the Azure.Storage.Files.Shares package to communicate with the Azure File Storage service. For more information see the Azure.Storage.Files.Shares authentication documentation.

Key concepts

The Azure Storage Common client library contains shared infrastructure like [authentication credentials][auth_credentials] and RequestFailedException.

Thread safety

We guarantee that all client instance methods are thread-safe and independent of each other (guideline). This ensures that the recommendation of reusing client instances is always safe, even across threads.

Additional concepts

Client options | Accessing the response | Long-running operations | Handling failures | Diagnostics | Mocking | Client lifetime

Examples

This section demonstrates usage of Data Movement for interacting with file shares.

Initializing File Share StorageResource

Azure.Storage.DataMovement.Files.Shares exposes ShareFilesStorageResourceProvider to create StorageResource instances for files and directories. The resource provider should be initialized with a credential to properly authenticate the storage resources. The following demonstrates this using an Azure.Core token credential.

ShareFilesStorageResourceProvider shares = new(tokenCredential);

To create a share StorageResource, use the methods FromFile or FromDirectory.

StorageResource directory = shares.FromDirectory(
    new Uri("http://myaccount.files.core.windows.net/share/path/to/directory"));
StorageResource rootDirectory = shares.FromDirectory(
    new Uri("http://myaccount.files.core.windows.net/share"));
StorageResource file = shares.FromFile(
    new Uri("http://myaccount.files.core.windows.net/share/path/to/file.txt"));

Storage resources can also be initialized with the appropriate client object from Azure.Storage.Files.Shares. Since these resources will use the credential already present in the client object, no credential is required in the provider when using FromClient(). However, a ShareFilesStorageResourceProvider must still have a credential if it is to be used in TransferManagerOptions for resuming a transfer.

ShareFilesStorageResourceProvider shares = new();
StorageResource shareDirectoryResource = shares.FromClient(directoryClient);
StorageResource shareFileResource = shares.FromClient(fileClient);

Upload

An upload takes place between a local file StorageResource as source and file share StorageResource as destination.

Upload a file.

DataTransfer fileTransfer = await transferManager.StartTransferAsync(
    sourceResource: files.FromFile(sourceLocalFile),
    destinationResource: shares.FromFile(destinationFileUri));
await fileTransfer.WaitForCompletionAsync();

Upload a directory.

DataTransfer folderTransfer = await transferManager.StartTransferAsync(
    sourceResource: files.FromDirectory(sourceLocalDirectory),
    destinationResource: shares.FromDirectory(destinationFolderUri));
await folderTransfer.WaitForCompletionAsync();

Download

A download takes place between a file share StorageResource as source and local file StorageResource as destination.

Download a file.

DataTransfer fileTransfer = await transferManager.StartTransferAsync(
    sourceResource: shares.FromFile(sourceFileUri),
    destinationResource: files.FromFile(destinationLocalFile));
await fileTransfer.WaitForCompletionAsync();

Download a Directory.

DataTransfer directoryTransfer = await transferManager.StartTransferAsync(
    sourceResource: shares.FromDirectory(sourceDirectoryUri),
    destinationResource: files.FromDirectory(destinationLocalDirectory));
await directoryTransfer.WaitForCompletionAsync();

File Copy

A copy takes place between two share StorageResource instances. Copying between two files or directories uses PUT from URL REST APIs, which do not transfer data through the machine running DataMovement.

Copy a single file.

DataTransfer fileTransfer = await transferManager.StartTransferAsync(
    sourceResource: shares.FromFile(sourceFileUri),
    destinationResource: shares.FromFile(destinationFileUri));
await fileTransfer.WaitForCompletionAsync();

Copy a directory.

DataTransfer directoryTransfer = await transferManager.StartTransferAsync(
    sourceResource: shares.FromDirectory(sourceDirectoryUri),
    destinationResource: shares.FromDirectory(destinationDirectoryUri));
await directoryTransfer.WaitForCompletionAsync();

Troubleshooting

TODO

Next steps

TODO

Contributing

See the Storage CONTRIBUTING.md for details on building, testing, and contributing to these libraries.

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit cla.microsoft.com.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Impressions