简体   繁体   中英

How to copy files from Azure File-Share (not blob) of different storage account using .net core

public void MoveFiles(AzureFileClient srcAzureClient, AzureFileClient destAzureClient, ShareClient srcShareClient, ShareClient destShareClient, string dirName)
{
    if (!destAzureClient.ShareClient.GetDirectoryClient(dirName).Exists())
        destAzureClient.ShareClient.GetDirectoryClient(dirName).Create();

    var fileItems = GetChildNodes(srcShareClient, dirName);

    if (fileItems.Count == 0)
        return;

    foreach (var item in fileItems)
    {
        if (item.ShareFileItem.IsDirectory)
        {
            MoveFiles(srcAzureClient, destAzureClient, srcShareClient, destShareClient, $"{dirName}/{item.ShareFileItem.Name}");
        }
        else
        {
            var srcFileClient = srcShareClient.GetDirectoryClient(Path.GetDirectoryName(item.FullPath)).GetFileClient(Path.GetFileName(item.FullPath));
            var destFileClient = destShareClient.GetDirectoryClient(Path.GetDirectoryName(item.FullPath)).GetFileClient(Path.GetFileName(item.FullPath)); 

            if (srcFileClient.Exists())
            {
                destFileClient.StartCopy(srcFileClient.Uri);
            }
        }
    }
}

This code is throwing an error at

destFileClient.StartCopy(srcFileClient.Uri) 

saying

sourceCopy is not verified, connection strings are given to both source & destination fileShare object

I am able to copy files from the same account storage.

When copying files (or blobs) across storage accounts, the source file (or blob) must be publicly accessible. This restriction does not apply when the source and destination are in the same storage account.

Because Azure Files are inherently private (there's no concept of ACL like we have in Blob Storage), you are getting this error as Azure Storage Service is not able to read the source file.

To fix this, you would need to create a SAS URL with at least read permission on the source file and use that SAS URL as copy source.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM