hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

problem accessing a share #583

Open stanislawantoniak opened 4 years ago

stanislawantoniak commented 4 years ago

I am accessing a share on a Windows server in a most canonical way - code listed below.

Error that I get is: Exception in thread "main" com.hierynomus.mssmb2.SMBApiException: STATUS_ACCESS_DENIED (0xc0000022): Could not connect to \{some host}.{some name}.net\SFTP-DEV at com.hierynomus.smbj.session.Session.connectTree(Session.java:180) at com.hierynomus.smbj.session.Session.connectShare(Session.java:151) at com.mars.App.(App.java:59) at com.mars.Main.main(Main.java:21)

Share and folder is accessible on windows explorer for the account that I am using.

When I connect to same host and a different share - BZT - I can connect seamlessly. There is no difference in permissions setup. The only thing I that comes to my mind is a dash used in share name. But a single dash is allowed in share names. And it looks like share name is recognized by the server.

Any clue what might be the reason? Or any hint on what to check?

SMBClient client = new SMBClient();

    Connection connection = client.connect(host);
    System.out.println("host connected: "+host);

    AuthenticationContext ac = new AuthenticationContext(username, password.toCharArray(), domain);
    Session session = connection.authenticate(ac);
    System.out.println("authenticated: "+username);

    // Connect to Share
    System.out.println("connecting to share: "+share);
    DiskShare diskShare = (DiskShare) session.connectShare(share);
    System.out.println("share acquired: "+share);

    for (FileIdBothDirectoryInformation f : diskShare.list(folder, FileIdBothDirectoryInformation.class,"*.*", EnumSet.of(AccessMask.MAXIMUM_ALLOWED))) {
        System.out.println("File : " + f.getFileName());
    }
hierynomus commented 4 years ago

STATUS_ACCESS_DENIED means that the authentication passed in does not have access to that share.

stanislawantoniak commented 4 years ago

Hi Jeroen - thanks for quick turnaround!

Any clue where to check share access?