用于网络共享的 Mono DirectoryInfo

发布于 2024-12-02 23:05:13 字数 844 浏览 2 评论 0原文

我在 VS2010 中编写了一个快速控制台应用程序,用于将文件从网络位置复制到磁盘上的指定位置。该程序在 Windows 上运行良好,但当我将其复制到 Mac 并针对 Mono 运行时执行它时,似乎无法打开网络共享。

我创建 DirectoryInfo 对象的代码如下所示:

var dir = new DirectoryInfo(@"\\nameofserver\location\to\file");

在 Windows 中,这可以正确解析为网络共享。在 Mac 中,它为我提供了二进制文件的相对路径(我从桌面运行它):

/Users/username/Desktop/\\nameofserver\location\to\file

我用 Google 搜索了一下一点点,它建议我的路径应该采用 smb://... 的形式。但是,即使我这样做,我的 DirectoryInfo 也会解析为:

/Users/username/Desktop/smb://nameofserver/location/to/file

我猜在那里要么是我缺少能够访问网络共享的语法,要么是它在 OSX 上不那么简单。不管怎样,我想知道如何连接到网络共享并下载文件。

谢谢!

编辑:

我尝试了//nameofserver/location/to/file。这有点帮助,只是它仍然没有解析网络共享引用,而是假设路径是本地路径:

/nameofserver/location/to/file

I wrote a quick console app in VS2010 to copy a file from a network location to a specified location on disk. The program works fine on Windows but when I copy it into the Mac and execute it against the Mono runtime, it seems to have trouble opening the network share.

My code to create a DirectoryInfo object looks like this:

var dir = new DirectoryInfo(@"\\nameofserver\location\to\file");

In Windows, this resolves correctly to the network share. In Mac, it gives me a relative path to the binary (I was running it from the Desktop):

/Users/username/Desktop/\\nameofserver\location\to\file

I did Google it a little bit and it suggested that my path should be of the form smb://.... However, even when I do this, my DirectoryInfo resolves to:

/Users/username/Desktop/smb://nameofserver/location/to/file

I'm guessing there is either a syntax I'm missing to be able to get access to the network share or that it isn't so straightforward on OSX. Either way, I'd like to know how to connect to the network share and download the file.

Thanks!

EDIT:

I tried //nameofserver/location/to/file. This helped somewhat, except that it still did not resolve the network share reference, instead assuming the path to be a local one:

/nameofserver/location/to/file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文