How do I use JCIFS with apache VFS to access an SMB URL - part 2?
Asked Answered
B

1

-1

I had the same problem: How do I use JCIFS with apache VFS to access an SMB URL?

... after including commons-vfs-sandbox-2.1-SNAPSHOT.jar in the classpath I now get this exception:

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

Please advice.

Blueweed answered 5/1, 2015 at 12:9 Comment(7)
The error seems rather self-explaining. What is your question?Hyperextension
I'm successfully writing files using the pure JCIFS API. It's just that I can't do it over commons-vfs. The problem is that the vfs api "could not determine the type of file smb://...". Why?Blueweed
Why? That error is (quote): "Caused by: jcifs.smb.SmbAuthException: Logon failure: account currently disabled.".Hyperextension
As I said, I can do it successfully using the jcifs-1.17 API with the same account, same credentials. The account is definitely not disabled. Something is wrong with the apache vfs smb provider. I might be missing a jar but I don't know which one. Please see: #11613190Blueweed
No it does not look like a JAR problem. It looks more like a configuration problem. How did you specify the username? bTW: you are not mixing VFS 2.0 with smb-provider 2.1, right?Alamode
I specify the username in the same way like in the referenced thread - using new StaticUserAuthenticator(<domain>,<user>,<password>); I'm using VFS 2.0 and commons-vfs-sandbox-2.1-SNAPSHOT. I don't know what smb-provider 2.1 is.Blueweed
You should not mix vfs-core 2.0 with vfs-sandbox 2.1. It is better to compile the 2.0 sandbox. The jcifs.Config.registerSmbURLHandler(); in the other question looks wrong. In the other stacktrace the URL provider was visible. You can check with System.out.println("prov? " + fs.hasProvider("smb")); after getManager() that your jcifs provider is actually loaded.Alamode
A
4

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).

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.

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

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>

to the already existing <resources> tag (right after first LICENSE+NOTICE include line 88)

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", "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());
    }
}

And this is the execution:

> 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
Alamode answered 5/1, 2015 at 13:42 Comment(2)
Excellent! Thank you very much for the detailed answer. It works by the book! Actually, it turns out that the problem was in my source code - I missed to add the opts: FileObject smbFile = fs.resolveFile(args[0], opts); // added opts!Blueweed
I just commited a fix for the missing vfs-provider.xml (VFS-552) to trunk, it will be in 2.1Alamode

© 2022 - 2024 — McMap. All rights reserved.