vfs2 and samba(smb) version 2



我们在Windows机器中禁用了SMBv1,现在无法使用SMB2进行连接我们正在使用Commons-VFS2(2.0(和Commons-VFS2-sandbox(2.0(这是我的代码:

@Test
    public void testConnection() throws FileSystemException {
         String folder = "\\10.0.0.0\smb";
        folder = folder.replaceAll("\\", "/");
        StringBuilder builder = new StringBuilder(128).append(Protocol.CIFS.getProtocolPrefix()).append(':')
                .append(folder);
        String fileURI = builder.toString();
        System.out.println(fileURI);
        FileSystemOptions fsOptions = null;
        String password = "mAdmin";
        String username = "myPassword";
        String domain = "";
        StaticUserAuthenticator auth = new StaticUserAuthenticator(domain, username, password);
        fsOptions = new FileSystemOptions();
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(fsOptions, auth);
        FileSystemManager manager = VFS.getManager();
        FileSystemManager fileSystemManager = manager;
        FileObject fileObject = fileSystemManager.resolveFile(fileURI, fsOptions);
        boolean result = fileObject.isReadable();
        System.out.println(fileURI +" " + result);
    }

这就是我禁用 SMB v1 的方式

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB1 -type DWORD -Value 0 -Force

如何启用 SMBV2

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" SMB2 -type DWORD -值 1 -强制

https://support.microsoft.com/en-us/help/2696547/how-to-enable-and-disable-smbv1-smbv2-and-smbv3-in-windows-and-windows-server

如果我们启用 SMB1,它正在工作

[追踪]

org.apache.commons.vfs2.FileSystemException: Could not determine if file "smb://10.0.0.0/smb/" is readable.
    at org.apache.commons.vfs2.provider.AbstractFileObject.isReadable(AbstractFileObject.java:1761)
    at com.pa.util.files.FileUtilsTest.testConnection(FileUtilsTest.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "smb://10.0.0.0/smb/".
    at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1526)
    at org.apache.commons.vfs2.provider.AbstractFileObject.exists(AbstractFileObject.java:1022)
    at org.apache.commons.vfs2.provider.AbstractFileObject.isReadable(AbstractFileObject.java:1757)
    ... 26 more
Caused by: jcifs.smb.SmbException: Failed to connect: 0.0.0.0<00>/10.0.0.0
jcifs.util.transport.TransportException
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at jcifs.util.transport.Transport.readn(Transport.java:29)
    at jcifs.smb.SmbTransport.peekKey(SmbTransport.java:388)
    at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:288)
    at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:319)
    at jcifs.util.transport.Transport.run(Transport.java:241)
    at java.lang.Thread.run(Thread.java:745)
    at jcifs.util.transport.Transport.run(Transport.java:258)
    at java.lang.Thread.run(Thread.java:745)
    at jcifs.smb.SmbTransport.connect(SmbTransport.java:309)
    at jcifs.smb.SmbTree.treeConnect(SmbTree.java:156)
    at jcifs.smb.SmbFile.doConnect(SmbFile.java:911)
    at jcifs.smb.SmbFile.connect(SmbFile.java:954)
    at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
    at jcifs.smb.SmbFile.exists(SmbFile.java:1415)
    at org.apache.commons.vfs2.provider.smb.SmbFileObject.doGetType(SmbFileObject.java:133)
    at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1517)
    ... 28 more

[绒球.xml]

       <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-vfs2</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-vfs2-sandbox</artifactId>
            <version>2.0</version>
        </dependency>

请帮忙

不幸的是,

commons-vfs2不支持SMBv2协议。SMBv2 客户端目前唯一的开源实现是 SMBJ。使用 SMBJ,您可以按如下方式连接到您的共享:

SMBClient client = new SMBClient(SmbConfig.createDefaultConfig());
Connection c = client.connect("10.0.0.0");
Session s = c.authenticate(new AuthenticationContext("myAdmin", "myPassword", "");
DiskShare share = s.connectShare("smb");

相关内容

  • 没有找到相关文章

最新更新