英文:
Discover shared folders for a given computer?
问题
我正在尝试发现并访问我网络中一台计算机(我们称之为ComputerA)共享的文件夹和文件。如果我知道ComputerA共享了一个名为Source的文件夹,我可以使用以下代码获取Source文件夹中的所有文件列表:
files, err := ioutil.ReadDir("\\\\ComputerA\\Source")
然而,我不能使用以下代码来查找Source(或任何其他共享文件夹):
files, err := ioutil.ReadDir("\\\\ComputerA")
似乎ioutil
无法使用UNC路径列出根共享文件夹。我已经快速查看了一下标准库中的其他包,但没有找到其他方法来实现这个功能。
据我所知,这不是权限问题。我可以打开资源管理器并直接访问\\ComputerA
,一切都正常。
除了以上方法,还有其他方式可以发现网络中特定计算机的共享文件夹吗?
英文:
I'm trying to discover and walk the shared folders and files of a computer on my network, let's call it ComputerA. If I know ComputerA is sharing a folder called Source, I can use
files, err := ioutil.ReadDir("\\\\ComputerA\\Source")
to get a list of all the files in Source. However, I can't do this to find Source (or any other shared folders)
files, err := ioutil.ReadDir("\\\\ComputerA")
It seems that ioutil
can't list the root shared folders using a UNC path like this. I've looked over the stock packages rather quickly and nothing else jumps out at me as a way to do this.
It's not a permissions issue as far as I can tell. I can open up explorer and go straight to \\ComputerA
and it'll work just fine.
How else can I discover the shared folders for a specific computer on my network?
答案1
得分: 3
这似乎不是Go库(如ioutil
或net
)或其他包直接支持的功能。
相反,这将取决于所使用的文件系统,并且最好使用系统命令(exec.Command().Output()
)。例如,在Windows中,可以使用net share
(用于本地共享)或net view
(用于远程共享)。
英文:
That doesn't seem directly supported by Go libraries like ioutil
or net
or other packages.
Instead that would depend on the file system used, and would best use a system command (exec.Command().Output()
).
For instance, for Windows, net share
(for local shares) or net view
(for remote shares).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论