【问题标题】:Connection Reset when attempting to list all files from a Sharefolder尝试列出共享文件夹中的所有文件时连接重置
【发布时间】:2019-10-09 13:15:14
【问题描述】:

我正在尝试使用SmbFile 和NtlmPasswordAuthentication 递归检查公司共享文件夹中的特定文件。

由于我对 Java 不是很了解,所以我遵循了在互联网上找到的示例,但每当我尝试执行 root.listFiles() 时,我都会收到以下错误:

jcifs.smb.SmbException: Failed to connect: foldername/xx.xx.xx.xxx
jcifs.util.transport.TransportException
java.net.SocketException: Connection reset


我确实拥有共享文件夹的访问权限,所以我最初的想法是我的代码中缺少某些东西,而是身份验证或代理错误。我使用以下格式的 url:smb://foldername/something/somethingelse/anothersomething/

我的代码:

    public static Boolean checkDiretory(String location, String docName){
        Boolean result = false;
        try {
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", Consts.username, Consts.password);
            SmbFile root = new SmbFile(location, auth);
            List<SmbFile> files = Arrays.asList(root.listFiles());
            for(SmbFile file : files){
                if(file.isDirectory()){
                    result = checkDiretory(file.getPath(), docName);
                    if(result)
                        return result;
                }
                else{
                    if(file.exists() && file.getName().contains(docName)){
                        return true;
                    }else{
                        result = false;
                    }
                }
            }
        } catch (SmbException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return result;
    }

【问题讨论】:

  • 你的目标服务器是什么?它可能不支持 SMB1。

标签: java samba smb ntlm-authentication


【解决方案1】:

就像 Eliad Cohen 建议的那样,由于 jcifs 中的 SMBv2 不兼容,您可能必须更改为 SMBJ。

我发现了一个类似的问题here,它可能会帮助您解决这个问题。

请记住,主机只是您的路径!

编码愉快!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多