将文件上传到 Azure 存储文件共享的脚本
Script to upload files to Azure Storage File Share
情况:
我刚刚创建了一个 Azure 存储文件共享,并且弄清楚了如何通过脚本 (C#) 将文件上传到 Azure BLOB 存储。
问题:
我想通过脚本将文件上传到我的 Azure 存储文件共享(不是 BLOB)。我已经安装了 Azure CLI,但问题是我必须先登录 (az login) 才能执行任何操作。
有什么方法可以将文件从基于我的 PC 的文件夹上传到 Azure 存储文件共享 (testuser.file.core.windows.net\test) 而无需安装它?
非常感谢。
有多个是为了完成这个。如果您唯一的问题是登录部分,那么您可以使用服务主体和证书来自动登录。
例子
az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p ~/mycertfile.pem --tenant contoso.onmicrosoft.com
您可以使用
查看更多选项
az login -h
希望对您有所帮助。
Is there any way to upload files from a folder based on my PC to the Azure storage file share (testuser.file.core.windows.net\test) without mounting it?
是的,我们也可以使用 C# 代码将文件上传到 Azure 文件存储。请尝试使用以下代码。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("storage connection string");
// Create a CloudFileClient object for credentialed access to File storage.
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("test");
share.CreateIfNotExists();
CloudFile cloudFile = share.GetRootDirectoryReference().GetFileReference("fileName");
Stream fileStream = File.OpenRead(@"localpath");
cloudFile.UploadFromStream(fileStream);
情况: 我刚刚创建了一个 Azure 存储文件共享,并且弄清楚了如何通过脚本 (C#) 将文件上传到 Azure BLOB 存储。
问题: 我想通过脚本将文件上传到我的 Azure 存储文件共享(不是 BLOB)。我已经安装了 Azure CLI,但问题是我必须先登录 (az login) 才能执行任何操作。
有什么方法可以将文件从基于我的 PC 的文件夹上传到 Azure 存储文件共享 (testuser.file.core.windows.net\test) 而无需安装它?
非常感谢。
有多个是为了完成这个。如果您唯一的问题是登录部分,那么您可以使用服务主体和证书来自动登录。
例子
az login --service-principal -u http://azure-cli-2016-08-05-14-31-15 -p ~/mycertfile.pem --tenant contoso.onmicrosoft.com
您可以使用
查看更多选项az login -h
希望对您有所帮助。
Is there any way to upload files from a folder based on my PC to the Azure storage file share (testuser.file.core.windows.net\test) without mounting it?
是的,我们也可以使用 C# 代码将文件上传到 Azure 文件存储。请尝试使用以下代码。
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("storage connection string");
// Create a CloudFileClient object for credentialed access to File storage.
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
// Get a reference to the file share we created previously.
CloudFileShare share = fileClient.GetShareReference("test");
share.CreateIfNotExists();
CloudFile cloudFile = share.GetRootDirectoryReference().GetFileReference("fileName");
Stream fileStream = File.OpenRead(@"localpath");
cloudFile.UploadFromStream(fileStream);