使用 C# 从 Ubuntu 访问网络路径
Accessing network path using C# from Ubuntu
我们用 C# 开发了一个应用程序。 Net 连接 Windows 网络路径并检查一个目录的可用性。当我们从 Windows OS 中 运行 应用程序时,它工作正常。但是当 运行 在 Ubuntu 16.04 OS 上安装它时,它无法识别 Windows 网络目录。
我们尝试了如下代码但没有成功,
Directory.Exists("\\xxx.xxx.x.xx\DirectoryName")
Directory.Exists(@"\xxx.xxx.x.xx\DirectoryName")
Directory.Exists("smb://xxx.xxx.x.xx/DirectoryName")
请建议我们如何将 C# 代码从 Ubuntu OS 修改为 运行。
如果你可以在运行之前在机器上设置环境,你可以尝试挂载网络路径然后使用它。
装载 SMB 共享 - 说明 from the Ubuntu Wiki 非常全面。
例如
mkdir ~/localMountPoint
mount -t cifs /xxx.xxx.x.xx/DirectoryName ~/localMountPoint -ou ser=myname,pass=mypassword
然后您可以使用:
Directory.Exists("~/localMountPoint/DirectoryName")
我们用 C# 开发了一个应用程序。 Net 连接 Windows 网络路径并检查一个目录的可用性。当我们从 Windows OS 中 运行 应用程序时,它工作正常。但是当 运行 在 Ubuntu 16.04 OS 上安装它时,它无法识别 Windows 网络目录。
我们尝试了如下代码但没有成功,
Directory.Exists("\\xxx.xxx.x.xx\DirectoryName")
Directory.Exists(@"\xxx.xxx.x.xx\DirectoryName")
Directory.Exists("smb://xxx.xxx.x.xx/DirectoryName")
请建议我们如何将 C# 代码从 Ubuntu OS 修改为 运行。
如果你可以在运行之前在机器上设置环境,你可以尝试挂载网络路径然后使用它。
装载 SMB 共享 - 说明 from the Ubuntu Wiki 非常全面。
例如
mkdir ~/localMountPoint
mount -t cifs /xxx.xxx.x.xx/DirectoryName ~/localMountPoint -ou ser=myname,pass=mypassword
然后您可以使用:
Directory.Exists("~/localMountPoint/DirectoryName")