使用 smb2 在 golang 中打开 Microsoft DFS 共享

M.H*_*ini 6 smb microsoft-distributed-file-system go

我在 Windows Server 2012 上有一个 dfs 共享。我可以在 Windows 文件资源管理器中打开共享并从另一个系统读取文件,路径如下:\\dfsserver\usernamespace\Tom\go.png。但是,通过https://github.com/hirochachacha/go-smb2使用 golang 的 smb2 包,我得到一个错误:

响应错误:联系的服务器不支持 DFS 命名空间的指示部分

但是,如果我尝试使用实际共享路径\\dfsserver\public share\Tom\go.png打开该文件,则代码可以正常工作。所以问题是我不知道运行时的实际路径,并且我希望能够使用 DFS 提供的路径打开文件。

难道是DFS在smb2上不能正常工作吗?或者其他一些问题。预先感谢您的评论。

    func main(){
    
        // actualPath := `\\dfsserver\public share\Tom\go.png`
        // dfsPath := `\\dfsserver\usernamespace\Tom\go.png`
    
        conn, err := net.Dial("tcp", fmt.Sprintf("%s:%s", "dfsserver", "445"))
        if err != nil {
            fmt.Println(err)
        }
        defer conn.Close()
    
        dial := &smb2.Dialer{
            Initiator: &smb2.NTLMInitiator{
                User:     "user",
                Password: "password",
                Domain:  "dfsserver",
            },
        }
        session, err := dial.Dial(conn)
        if err != nil {
            fmt.Println(err)
        }
        defer session.Logoff()
    
        mountPoint, err := session.Mount("usernamespace")
        if err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
    
       // error occures here, if the mountPoint was "public share" instead of "usernamespace" then no error
        remoteFile, err := mountPoint.Open(`Tom\go.png`) 
        defer remoteFile.Close()
        if err != nil {
            fmt.Println(err)
        }
    }
Run Code Online (Sandbox Code Playgroud)