如何使用 C# 从 Windows 服务访问 Linux 目录/文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2555046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access Linux directories/files from a Windows Service using C#
提问by Lenard
I have a C# Windows Service that needs to access to a Linux computer to get a list of files in a particular directory. What .NET 3.5SP1 method would one use that allows me to do this?
我有一个 C# Windows 服务,它需要访问 Linux 计算机以获取特定目录中的文件列表。什么 .NET 3.5SP1 方法可以让我这样做?
Thanks.
谢谢。
回答by Justin Niessner
You'll have to create a Samba (SMB) or NFS share on the Linux box that is accessible from the Windows machine that is running your application.
您必须在 Linux 机器上创建一个 Samba (SMB) 或 NFS 共享,它可以从运行您的应用程序的 Windows 机器访问。
You can then use the standard tools for working with files/directories in .NET to work with the files.
然后,您可以使用在 .NET 中处理文件/目录的标准工具来处理这些文件。
As mentioned in comments, you could also use the standard FTP libraries which would require configuring an FTP server on your Linux machine. SFTP is also an option...but would require a third party library on the .NET side.
正如评论中提到的,您还可以使用标准的 FTP 库,这需要在您的 Linux 机器上配置 FTP 服务器。SFTP 也是一种选择……但需要 .NET 端的第三方库。
回答by Justin Niessner
Hi you can check at my open source project http://code.google.com/p/nekodriveYou can use directly NekoDrive.NFS c# library that wraps my implementation of V2 e V3 NFS Protocol (V4.1 is coming).. It doesn't support the full protocol yet but It works for basic browsing/download/upload functions..
嗨,您可以查看我的开源项目http://code.google.com/p/nekodrive您可以直接使用 NekoDrive.NFS c# 库,该库包装了我对 V2 e V3 NFS 协议的实现(V4.1 即将推出)。它还不支持完整的协议,但它适用于基本的浏览/下载/上传功能..
hope this helps
希望这可以帮助