如何将 JCIFS 与 apache VFS 结合使用来访问 SMB URL - 第 2 部分?
How do I use JCIFS with apache VFS to access an SMB URL - part 2?
我遇到了同样的问题:
How do I use JCIFS with apache VFS to access an SMB URL?
...在类路径中包含 commons-vfs-sandbox-2.1-SNAPSHOT.jar 之后我现在得到这个异常:
Exception in thread "main" org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "smb://10.10.18.210/CIFS/123/asd".
at org.apache.commons.vfs2.provider.AbstractFileObject.attach(AbstractFileObject.java:1522)
at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:489)
at org.apache.commons.vfs2.provider.AbstractFileObject.exists(AbstractFileObject.java:477)
at VFSTest.main(VFSTest.java:19)
Caused by: jcifs.smb.SmbAuthException: Logon failure: account currently disabled.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:549)
at jcifs.smb.SmbTransport.send(SmbTransport.java:667)
at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)
at jcifs.smb.SmbSession.send(SmbSession.java:218)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)
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.queryPath(SmbFile.java:1335)
at jcifs.smb.SmbFile.exists(SmbFile.java:1417)
at jcifs.smb.SmbFile.isDirectory(SmbFile.java:1490)
at org.apache.commons.vfs2.provider.smb.SmbFileObject.createSmbFile(SmbFileObject.java:118)
at org.apache.commons.vfs2.provider.smb.SmbFileObject.doAttach(SmbFileObject.java:70)
at org.apache.commons.vfs2.provider.AbstractFileObject.attach(AbstractFileObject.java:1505)
... 3 more
请指教
我想我知道你的问题是什么,沙箱提供者在 2.0 中没有自动注册。而且您还需要在解析调用中实际使用配置的身份验证属性(请参阅下面修改后的源代码)。
我通常不使用默认的文件系统管理器,而是动态注册我的提供程序,但如果你想使用自动检测,你需要将 vfs-providers.xml 添加到沙箱 JAR。
这就是使用 2.0 构建完整工作 JAR 的方式:
> git clone https://github.com/apache/commons-vfs.git -b commons-vfs2-project-2.0 vfs2.0
> cd vfs2.0
> notepad sandbox\pom.xml
> notepad sandbox\src\test\java\org\apache\commons\vfs2\provider\smb\test\StandaloneMain.java
> mvn -Pinclude-sandbox -DskipTests=true clean package dependency:tree
当您编辑 sandbox/pom.xml 时,您需要确保从 和 标签中删除 -SANDBOX。然后你需要添加:
<resource>
<directory>src/main/resources</directory>
</resource>
到已经存在的 标签(在第一个 LICENSE+NOTICE 包含第 88 行之后)
这是使用的测试代码:
package org.apache.commons.vfs2.provider.smb.test;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
public class StandaloneMain
{
public static void main(String[] args) throws FileSystemException {
//jcifs.Config.registerSmbURLHandler();
StaticUserAuthenticator auth = new StaticUserAuthenticator("DOMAIN", "eckenfel", "SECRET");
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileSystemManager fs = VFS.getManager();
if (!fs.hasProvider("smb")) throw new RuntimeException("Provide missing");
System.out.println("Connecting " + args[0] + " with " + opts);
FileObject smbFile = fs.resolveFile(args[0], opts); // added opts!
System.out.println(smbFile.exists() + " " + smbFile.getContent().getLastModifiedTime());
}
}
这是执行:
> set REP=C:\Users\USERNAME\.m2\repository
> java -cp sandbox\target\commons-vfs2-sandbox-2.0.jar;^
core\target\commons-vfs2-2.0.jar;^
%REP%\commons-logging\commons-logging.1.1\commons-logging-1.1.1.jar;^
%REP%\jcifs\jcifs[=13=].8.3\jcifs-0.8.3.jar;^
sandbox\target\test-classes
org.apache.commons.vfs2.provider.smb.test.StandaloneMain smb://HOST/Users
Jan 05, 2015 2:40:19 PM org.apache.commons.vfs2.VfsLog info
INFORMATION: Using "C:\Users\USERNAME\AppData\Local\Temp\vfs_cache" as temporary files store.
Connecting smb://eckenfels02/Users with org.apache.commons.vfs2.FileSystemOptions@27dd2ec5
true 0
我遇到了同样的问题: How do I use JCIFS with apache VFS to access an SMB URL?
...在类路径中包含 commons-vfs-sandbox-2.1-SNAPSHOT.jar 之后我现在得到这个异常:
Exception in thread "main" org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "smb://10.10.18.210/CIFS/123/asd".
at org.apache.commons.vfs2.provider.AbstractFileObject.attach(AbstractFileObject.java:1522)
at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:489)
at org.apache.commons.vfs2.provider.AbstractFileObject.exists(AbstractFileObject.java:477)
at VFSTest.main(VFSTest.java:19)
Caused by: jcifs.smb.SmbAuthException: Logon failure: account currently disabled.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:549)
at jcifs.smb.SmbTransport.send(SmbTransport.java:667)
at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)
at jcifs.smb.SmbSession.send(SmbSession.java:218)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)
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.queryPath(SmbFile.java:1335)
at jcifs.smb.SmbFile.exists(SmbFile.java:1417)
at jcifs.smb.SmbFile.isDirectory(SmbFile.java:1490)
at org.apache.commons.vfs2.provider.smb.SmbFileObject.createSmbFile(SmbFileObject.java:118)
at org.apache.commons.vfs2.provider.smb.SmbFileObject.doAttach(SmbFileObject.java:70)
at org.apache.commons.vfs2.provider.AbstractFileObject.attach(AbstractFileObject.java:1505)
... 3 more
请指教
我想我知道你的问题是什么,沙箱提供者在 2.0 中没有自动注册。而且您还需要在解析调用中实际使用配置的身份验证属性(请参阅下面修改后的源代码)。
我通常不使用默认的文件系统管理器,而是动态注册我的提供程序,但如果你想使用自动检测,你需要将 vfs-providers.xml 添加到沙箱 JAR。
这就是使用 2.0 构建完整工作 JAR 的方式:
> git clone https://github.com/apache/commons-vfs.git -b commons-vfs2-project-2.0 vfs2.0
> cd vfs2.0
> notepad sandbox\pom.xml
> notepad sandbox\src\test\java\org\apache\commons\vfs2\provider\smb\test\StandaloneMain.java
> mvn -Pinclude-sandbox -DskipTests=true clean package dependency:tree
当您编辑 sandbox/pom.xml 时,您需要确保从
<resource>
<directory>src/main/resources</directory>
</resource>
到已经存在的
这是使用的测试代码:
package org.apache.commons.vfs2.provider.smb.test;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
public class StandaloneMain
{
public static void main(String[] args) throws FileSystemException {
//jcifs.Config.registerSmbURLHandler();
StaticUserAuthenticator auth = new StaticUserAuthenticator("DOMAIN", "eckenfel", "SECRET");
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileSystemManager fs = VFS.getManager();
if (!fs.hasProvider("smb")) throw new RuntimeException("Provide missing");
System.out.println("Connecting " + args[0] + " with " + opts);
FileObject smbFile = fs.resolveFile(args[0], opts); // added opts!
System.out.println(smbFile.exists() + " " + smbFile.getContent().getLastModifiedTime());
}
}
这是执行:
> set REP=C:\Users\USERNAME\.m2\repository
> java -cp sandbox\target\commons-vfs2-sandbox-2.0.jar;^
core\target\commons-vfs2-2.0.jar;^
%REP%\commons-logging\commons-logging.1.1\commons-logging-1.1.1.jar;^
%REP%\jcifs\jcifs[=13=].8.3\jcifs-0.8.3.jar;^
sandbox\target\test-classes
org.apache.commons.vfs2.provider.smb.test.StandaloneMain smb://HOST/Users
Jan 05, 2015 2:40:19 PM org.apache.commons.vfs2.VfsLog info
INFORMATION: Using "C:\Users\USERNAME\AppData\Local\Temp\vfs_cache" as temporary files store.
Connecting smb://eckenfels02/Users with org.apache.commons.vfs2.FileSystemOptions@27dd2ec5
true 0