简体   繁体   English

当应用程序托管在 windows VM 中的 IIS 上时,无法将文件复制到 Azure 文件共享安装的驱动器

[英]Not able to copy file to Azure file share mounted drive when application hosted on IIS in windows VM

I have created windows virtual machine and mounted Azure file share drive as **Z:**.我创建了 windows 虚拟机并将 Azure 文件共享驱动器安装为 **Z:**。 My storage account name is onegbuploadfileshare and file share name is onefileshare .我的存储帐户名称是onegbuploadfileshare ,文件共享名称是onefileshare

I have written a code to write local folder file into Azure file share.我写了一个代码将本地文件夹文件写入 Azure 文件共享。 (Code Ref: https://learn.microsoft.com/en-us/do.net/api/overview/azure/storage.files.shares-readme?view=azure-do.net ). (代码参考: https://learn.microsoft.com/en-us/do.net/api/overview/azure/storage.files.shares-readme?view=azure-do.net )。 Then hosted the application on IIS in windows VM.然后将应用程序托管在 windows VM 中的 IIS 上。

But local file not get copied to Azure file share.但是本地文件不会复制到 Azure 文件共享。

My source file path is C:\pubish\Files\1gb.test and destination file path is @"z:\temp\newfile.test" where z drive is mounted drive.我的源文件路径是 C:\pubish\Files\1gb.test 目标文件路径是 @"z:\temp\newfile.test" 其中 z 驱动器是挂载驱动器。

I also programmatically tried with我也以编程方式尝试过

  1. Dos copy command approach processStartInfo.Arguments = @"/C copy /a C:\pubish\Files\1gb.test \onegbuploadfileshare.file.core.windows.net\onefileshare\temp" or /C copy /a C:\pubish\Files\1gb.test Z:\onefileshare\temp\ dos复制命令方式 processStartInfo.Arguments = @"/C copy /a C:\pubish\Files\1gb.test \onegbuploadfileshare.file.core.windows.net\onefileshare\temp" or /C copy /a C:\pubish \Files\1gb.test Z:\onefileshare\temp\

  2. ShareClient approach ShareClient 方法

  3. Az copy approach az复制方法

But not able to save file to file share in any approach.但无法以任何方式将文件保存到文件共享。 Code is working for c:\source to c:\dest file copy.代码适用于 c:\source 到 c:\dest 文件副本。

Did I miss something on IIS or code?我是不是漏掉了 IIS 或代码? Can anyone provide the solution.任何人都可以提供解决方案。

I am able to upload files using AZ Copy and by creating a share in Azure by following the below steps.我可以使用 AZ Copy 上传文件,并按照以下步骤在 Azure 中创建共享。

Using Az-copy copied the file to the Azure container.使用 Az-copy 将文件复制到 Azure 容器。

在此处输入图像描述

File copied to azure portal.文件复制到azure传送门。

在此处输入图像描述

            string filePath = @"C:\Temp\sample.txt";
            string azurePath = "https://storagerajesh114.blob.core.windows.net/sample/sample.txt";
            string key = "Storage Access Key";

            string cmd = $"AzCopy /Source:{filePath} /Dest:{azurePath} /DestKey:{key} /S";

            using (Process proc = new Process())
            {
                proc.StartInfo.FileName = "cmd.exe";
                proc.StartInfo.Arguments = $"/C {cmd}";
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.CreateNoWindow = true;
                proc.Start();
                proc.WaitForExit();
                Console.WriteLine(proc.StandardOutput.ReadToEnd());
            }
       

Created a share and uploaded a file using the below code.使用以下代码创建共享并上传文件。


string connectionString = "Connection_String";

            string shareName = "share";
            string dirName = "Test";
            string fileName = "sample-file";

            string localFilePath = @"C:\Temp\sample.txt";

            ShareClient share = new ShareClient(connectionString, shareName);
            share.Create();

            ShareDirectoryClient directory = share.GetDirectoryClient(dirName);
            directory.Create();

            ShareFileClient file = directory.GetFileClient(fileName);
            using (FileStream stream = File.OpenRead(localFilePath))
            {
                file.Create(stream.Length);
                file.UploadRange(
                    new HttpRange(0, stream.Length),
                    stream);
            }

You need to use the connection string in the code mentioned in the below screenshots.您需要在以下屏幕截图中提到的代码中使用连接字符串。

在此处输入图像描述

在此处输入图像描述

Copy the connection string and use it in the code.复制连接字符串并在代码中使用它。

在此处输入图像描述

The share folder is created.共享文件夹已创建。

在此处输入图像描述

在此处输入图像描述

References taken from Azure Storage File Shares client引用自Azure 存储文件共享客户端

and

AzCopy 复制

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 文件资源管理器在尝试访问时挂起已安装 Azure Windows 10 桌面上的文件共享 - File Explorer hangs when trying access Mounted Azure File share on Windows 10 Desktop 无论如何要在 Azure VM(Windows)中的特定路径下载特定文件/文件夹 - Is there anyway to download a particular file/folder at a certain path in an Azure VM(Windows) 无法将 .bacpac 文件从 Azure VM 上传到 Azure blob 存储容器 - Not able to upload the .bacpac file from Azure VM to Azure blob storage container 在 Function 中从挂载共享复制文件比在启动中慢得多 - Copying file from mounted share much slower in Function than in Startup 如何与组织内的利益相关者共享 Azure 文件共享数据? - How to share Azure File Share data with the stakeholder within the organization? 无法将文件共享从 azure 连接到 windows 笔记本电脑,端口 445 被阻止 - Cannot connect file share from azure to windows laptop, port 445 is blocked 导航到 Terraform 在 Azure 创建的文件共享 - Navigate to file share created by Terraform in Azure azure 文件共享 map 到基于客户端的文件夹? - azure file share map to folder based on clients? 从外部 VM 在 Azure Win VM 上执行 bat 文件并由 Azure Function 触发的最佳和最安全的方法是什么 - What is the best and securest way to execute bat file on a Azure Win VM from outside VM and triggered by an Azure Function Azure 数据工厂 - 复制数据正在将 excel 文件转换为应用程序/八位字节流 - Azure Data Factory - Copy data is converting excel file to application/octet-stream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM