【问题标题】:How to Access Shared Network Drive from Azure webjob如何从 Azure webjob 访问共享网络驱动器
【发布时间】:2018-11-21 19:15:01
【问题描述】:

尝试使用来自 Web 作业的 UNC 路径访问共享网络驱动器时出现访问被拒绝错误。 我正在尝试从客户端服务器上的共享文件夹和 SFTP 读取文件。 从本地,能够访问所有文件工作正常。但是从 azure web job 获取访问被拒绝错误到文件夹。 这是我的代码:

 var con = new ConnectionInfo(host, 22, username, methods.ToArray());
                using (var client = new SftpClient(con))
                {
                    Console.WriteLine("Connecting to client");
                    client.Connect();
                    Console.WriteLine("Connected to client");
                    Console.WriteLine("Getting file from Azure ");
                    string tstkey1 = File.ReadAllText(@"\\{shared folder}\test\test.txt");
                    Console.WriteLine("Connected");
                    string tstkey = File.ReadAllText(@"\\{shared folder}\test\test.txt");
                    Console.WriteLine(tstkey);                  
                    byte[] fileContents = Encoding.UTF8.GetBytes(tstkey);
                    Stream requestStream = new MemoryStream(fileContents);
                    Console.WriteLine(requestStream);
                    Console.WriteLine("Uploading to FILE to client SFTP");
                    client.UploadFile(requestStream, "/inbound/STEIN366_ACH_1/*.*" + "Test");
                    client.Disconnect();
                    Console.WriteLine("Deleting File");
                    File.Delete(@"\\{folder}\test\test.txt");
                    Console.WriteLine("Dissconnected from client");
                }  

谁能帮助我,如何从 Azure 连接到共享文件夹! 提前致谢。

【问题讨论】:

  • 您的问题标题为“共享网络驱动器”。您的代码用于 SFTP。那么你真正要问的是什么? + 向我们展示您的确切异常错误消息和堆栈跟踪。
  • @MartinPrikryl :这是我尝试从共享驱动器读取文件的代码。 string tstkey = File.ReadAllText(@"\\{Shared Drive}\test\test.txt"); Console.WriteLine(tstkey); byte[] fileContents = Encoding.UTF8.GetBytes(tstkey); Stream requestStream = new MemoryStream(fileContents);
  • @MartinPrikryl:错误消息错误消息[ERR ] Unhandled Exception: System.UnauthorizedAccessException: Access to the path '\\{Shared Folder}\test\test.txt' is denied. [ ERR ] at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) [ ERR ] at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
  • 编辑您的问题 为 1) 仅显示相关代码(无 SFTP)。 2) 显示异常详细信息 3) 解释为什么您认为 WebJob 应该能够访问 UNC 路径 + 删除上面的 cmets。

标签: azure azure-webjobs


【解决方案1】:

如果您想使用 SFTP 传输文件,您可以使用 WinSCP .NET Assembly

这是使用WinSCPguide。而你可以参考这个answer关于WinSCP的使用。

如果您仍有疑问,请告诉我。

【讨论】:

    猜你喜欢
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多