gpt4 book ai didi

c# - AzCopy V10 复制文件

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:52 31 4
gpt4 key购买 nike

我在尝试使用 C# 中的 AzCopy V10 将 blob 从一个容器复制到另一个容器时遇到问题。

当我通过命令行编写代码时,我可以毫无问题地传输文件,但是当我尝试在 C# 中执行相同的操作时,我收到身份验证错误。

错误信息

failed to perform copy command due to error: cannot start job due to error: cannot list blobs, -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /home/vsts/go/pkg/mod/github.com/!azure/azure-storage-blob-go@v0.7.0/azblob/zc_storage_error.go:42
===== RESPONSE ERROR (ServiceCode=AuthorizationPermissionMismatch) =====
Description=This request is not authorized to perform this operation using this permission.
Time:2019-08-16T10:21:18.0483745Z, Details:
Code: AuthorizationPermissionMismatch
User-Agent: [AzCopy/10.2.1 Azure-Storage/0.7 (go1.12; Windows_NT)]
--------------------------------------------------------------------------------
RESPONSE Status: 403 This request is not authorized to perform this operation using this permission.
Content-Length: [279]
Content-Type: [application/xml]
Date: [Fri, 16 Aug 2019 10:21:17 GMT]
Server: [Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0]
X-Ms-Error-Code: [AuthorizationPermissionMismatch]
X-Ms-Version: [2018-11-09]

我的代码如下。

SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy
{
SharedAccessStartTime = DateTimeOffset.UtcNow.AddDays(-1),
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddDays(1), // 1 day expired
Permissions = SharedAccessBlobPermissions.Read //Read & Write
};
// var createFolder = items.GetBlockBlobReference(items.Name);

var AzCopyProcess = new Process();
AzCopyProcess.StartInfo.UseShellExecute = false;
AzCopyProcess.StartInfo.RedirectStandardOutput = true;
AzCopyProcess.StartInfo.FileName = strCommand;
//pass storage account name, container and the key
// Debug.WriteLine($"azcopy cp \"{items.Uri}{items.GetSharedAccessSignature(sasConstraints)}\" \"{dayBlob.Uri}{dayBlob.GetSharedAccessSignature(sasConstraints)}\" --recursive");
AzCopyProcess.StartInfo.Arguments = $"copy \"{items.Uri}{items.GetSharedAccessSignature(sasConstraints)}\" {" "} \"{dayBlob.Uri}{dayBlob.GetSharedAccessSignature(sasConstraints)}\" --recursive";
AzCopyProcess.Start();
StreamWriter stdOut = new StreamWriter(Console.OpenStandardOutput());
stdOut.AutoFlush = true;
Console.Write(stdOut);
var output = AzCopyProcess.StandardOutput.ReadToEnd();
Console.WriteLine($"{items.Name} {output}");

最佳答案

对于源,您需要将权限设置为读取和列出,以便它扫描文件。

Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List

对于目的地,您需要获得写入权限。

Permissions = SharedAccessBlobPermissions.Write

由于您只使用一个 SASPolicy,因此您可以将它们结合起来,尽管这确实意味着 SAS token 会提供一些该过程不需要的额外权限。

 Permissions = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.List | SharedAccessBlobPermissions.Write

关于c# - AzCopy V10 复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57523100/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com