vfs2 和 samba(smb) 版本 2
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 -Value 1 -Force
如果我们启用 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.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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.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
[pom.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");
我们在 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 -Value 1 -Force
如果我们启用 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.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.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.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
[pom.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");