问题描述
我试图访问使用SMB URL我的本地计算机上的文件夹。
我的项目使用的罐子:公地vfs2-2.0.jar和JCIFS-1.3.17.jar(和所有其他所需的罐子)。
在它的整体code是:
I am trying to access a folder on my local computer using an smb URL.my project is using the jars: commons-vfs2-2.0.jar and jcifs-1.3.17.jar (and all the other required jars).The code in it's entirety is:
public static void main(String[] args) throws FileSystemException {
jcifs.Config.registerSmbURLHandler();
StaticUserAuthenticator auth = new StaticUserAuthenticator(<domain>,<user>,<password>);
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileSystemManager fs = VFS.getManager();
FileObject smbFile = fs.resolveFile("smb://10.0.2.2/TimeOut/");
System.out.println(smbFile.exists() + " " + smbFile.getContent().getLastModifiedTime());
}
我收到了异常:
异常线程main
org.apache.commons.vfs2.FileSystemException:无法确定
文件类型SMB://10.0.2.2/TimeOut。在
org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:505)
在
org.apache.commons.vfs2.provider.AbstractFileObject.exists(AbstractFileObject.java:477)
在com.newsway.tests.VfsTest.main(VfsTest.java:23)引起的:
jcifs.smb.SmbAuthException:登录失败:禁用当前的帐户。
在jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:546)在
jcifs.smb.SmbTransport.send(SmbTransport.java:663)在
jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)在
jcifs.smb.SmbSession.send(SmbSession.java:218)在
jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)在
jcifs.smb.SmbFile.doConnect(SmbFile.java:911)在
jcifs.smb.SmbFile.connect(SmbFile.java:954)在
jcifs.smb.SmbFile.connect0(SmbFile.java:880)在
jcifs.smb.SmbFile.open0(SmbFile.java:972)在
jcifs.smb.SmbFile.open(SmbFile.java:1006)在
jcifs.smb.SmbFileInputStream(SmbFileInputStream.java:73)在
jcifs.smb.SmbFileInputStream(SmbFileInputStream.java:65)在
jcifs.smb.SmbFile.getInputStream(SmbFile.java:2844)在
org.apache.commons.vfs2.provider.url.UrlFileObject.doGetType(UrlFileObject.java:89)
在
org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:496)
从中我了解到,相关部分是:登录失败:禁用当前的帐户的
from which I understand that the relevant part is: Logon failure: account currently disabled.
尽管这是一个事实,我的用户名/密码/域都很好,我做什么在VFS文档页面定义。
This is despite the fact that my user/password/domain are fine and I am doing exactly what is defined in the VFS documentation page.
我是什么失踪?
推荐答案
我想我知道你的问题是什么,沙箱供应商不会自动在2.0注册。并且还需要实际使用中的解析调用配置的认证属性(见下文修改源)。
I think I know what your problem is, the sandbox providers are not registered automatically in 2.0. And also you need to actually use the configured authentication properties in the resolve call (see modified source below).
我通常不使用默认文件系统管理器,但动态地注册我的供应商,但如果你想使用自动检测,你需要VFS-providers.xml添加到沙箱JAR。
I typically not use the default filesystem manager but register my providers dynamically, but if you want to use the automatic detection, you need to add vfs-providers.xml to the sandbox JAR.
这是你如何建立一个完整的工作JAR 2.0:
This is how you build a complete working JAR with 2.0:
> 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
在编辑沙盒/ pom.xml的,你需要确保来自以下删除-SANDBOX;版本>和&lt;父母>&LT;版>标记。然后,你需要添加:
When you edit the sandbox/pom.xml, you need to make sure to remove -SANDBOX from <version> and <parent><version> tags. Then you need to add:
<resource>
<directory>src/main/resources</directory>
</resource>
到已经存在&LT;资源>标签(头牌+通知后右包括线路88)
to the already existing <resources> tag (right after first LICENSE+NOTICE include line 88)
这是用来测试code:
This is the test code used:
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", "user", "SECRET");
FileSystemOptions opts = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
FileSystemManager fs = VFS.getManager();
if (!fs.hasProvider("smb")) throw new RuntimeException("Provider 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.1\commons-logging-1.1.1.jar;^
%REP%\jcifs\jcifs\0.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
这篇关于我如何使用JCIFS与Apache VFS访问一个SMB网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!