hierynomus / smbj

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

can't connect share in sub directory #549

Closed faizananwerali closed 3 years ago

faizananwerali commented 4 years ago

can't connect share in sub directory. see (DiskShare) session.connectShare("Softwares/Chating")

public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    @SuppressWarnings("resource")
    SMBClient client = new SMBClient();

    try (Connection connection = client.connect("10.100.0.5")) {
        AuthenticationContext ac = new AuthenticationContext("", "".toCharArray(), "WORKGROUP");
        Session session = connection.authenticate(ac);

        // Connect to Share
        try (DiskShare share = (DiskShare) session.connectShare("Softwares/Chating")) {
            for (FileIdBothDirectoryInformation f : share.list("")) {
                System.out.println("File : " + f.getFileName());
            }           
        }
    }
}

Error:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Exception in thread "main" com.hierynomus.mssmb2.SMBApiException: STATUS_BAD_NETWORK_NAME (0xc00000cc): Could not connect to \10.100.0.5\Softwares/Chating at com.hierynomus.smbj.session.Session.connectTree(Session.java:180) at com.hierynomus.smbj.session.Session.connectShare(Session.java:151) at imdb.Start.main(Start.java:24)

ecki commented 4 years ago

Shares are normally not hierarchical, are you sure that / is correct? If it is a subdir of the share, you do not specify it in the connect.

neoxpert commented 4 years ago

If Chating is a subfolder of the share Softwares you have to connect to the share Softwares and from there use relative paths to the folders / files you want to access. You can not connect to the subfolder Chating as it is not a share by itself.

This might be a bit confusing if you previously used libs like JCIFS as the magic of resolving what is a share and what is a directory is hidden away from you while SMBJ is a bit closer to the actual protocol.

hierynomus commented 4 years ago

@faizananwerali Is your question answered? If yes, please close this issue.

hierynomus commented 3 years ago

Closing due to no response.