【发布时间】: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