我们希望在Windows Azure中迁移我们的FTP服务器 . 我们创建了干净的虚拟机映像并在那里安装了FTP Server . 现在,为了能够直接从Windows Azure数据中心处理驻留在FTP目录中的文件,我们创建了文件共享和 endpoints (端口445 TCP和UDP) . 如果我们试图从工作者角色访问FTP服务器的文件共享,我们通常会得到'Access to the path ' ... ' is denied.' . 我们可以通过远程桌面从Worker Role访问FTP Server的文件共享,这意味着防火墙和FTP配置是正确的 . 工作者角色可以访问Windows Azure数据中心中的文件共享吗?
代码:
try
{
const string networkShare = @"...";
Directory.GetFiles(networkShare).ToList().ForEach(file => Trace.TraceInformation(file));
Thread.Sleep(10000);
Trace.WriteLine("Working", "Information");
}
catch (Exception ex)
{
Trace.TraceError(ex.ToString());
}
例外:
Exception thrown on running: System.UnauthorizedAccessException: Access to the path '...' is denied.
Server stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileSystemEnumerableIterator`1.CommonInit()
at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption, Boolean checkHost)
at System.IO.Directory.InternalGetFiles(String path, String searchPattern, SearchOption searchOption)
at KALCIK.NET.Plugin.ReadFromShare.ReadFromSharePlugin.Manipulate(String valueToManipulate)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at KALCIK.NET.Plugin.Contracts.TextManipulationPluginBase.Manipulate(String valueToManipulate)
at KALCIK.NET.CloudServices.WorkerRole.BusinessLayers.WorkOrderProcessing.ProcessWorkOrder(Tuple`2 workOrder) in c:\Development\Samples\CloudServicesPlugInSample\CloudServices.WorkerRole\BusinessLayers\WorkOrderProcessing.cs:line 56
at KALCIK.NET.CloudServices.WorkerRole.WorkOrderProcessorService.Run() in c:\Development\Samples\CloudServicesPlugInSample\CloudServices.WorkerRole\WorkOrderProcessorService.cs:line 67; TraceSource 'WaWorkerHost.exe' event
2 回答
我认为这是一个安全问题:用户(运行工作角色的用户)无法在网络共享上进行身份验证 . 在Directory.GetFiles之前尝试“net use”
来自C#的"net use":Access a Remote Directory from C#
是的问题似乎是用户,在主机进程正在运行 . 要解决此问题,您可以使用管理员权限创建新用户(例如,在角色启动时借助启动任务)并模拟已执行的代码 . 您可以看到示例实现here .