Open abhisheksardana opened 3 years ago
Please refrain from @-mentioning me in issues. I'm not a maintainer of this project.
Please give full piece of code, what version of SMBJ are you using.
I have used SMBJ library for Connecting to NFS share.
Thanks, R Ramarajan.
Hello @vrr6,
Thanks for your reply. We are using SMBJ 0.10.0.
Here is the sample code which just list the files in the DFS share and one level down in the DFS share. (NFS share link is inside the DFS share). Please have a look.
Sample code:
public class SmbjPoc { private String ipAddress = "dfsShareIP"; private String username = "user"; private String password = "password"; private String domain = "domain"; private String shareName = "dfsShare";
private SMBClient client;
private Connection connection;
private Session session;
private DiskShare share;
private void connect() throws IOException {
SmbConfig config = SmbConfig.builder().withDfsEnabled(true).build();
client = new SMBClient(config);
connection = client.connect(ipAddress);
session = connection.authenticate(new AuthenticationContext(username, password.toCharArray(), domain));
share = (DiskShare) session.connectShare(shareName);
if (share.isConnected()) {
System.out.println("Successfully mounted share " + share.getSmbPath());
} else
System.out.println("Could not mount share " + share.getSmbPath());
}
private void relaseResources() throws IOException {
if (null != share)
share.close();
if (null != session)
session.close();
if (null != connection)
connection.close();
if (null != client)
client.close();
}
private void iterateDirectory() throws IOException {
for (FileIdBothDirectoryInformation f : share.list("")) { //List the files in root dfs share
System.out.println(f.getFileName());
if (f.getFileName().equals(".") || f.getFileName().equals(".."))
continue;
if (EnumWithValue.EnumUtils.isSet(f.getFileAttributes(), FileAttributes.FILE_ATTRIBUTE_REPARSE_POINT))
for (FileIdBothDirectoryInformation f1 : share.list(f.getFileName())) { // Here it is failing in case of NFS share but no issues observed with DFS or other smb shares
System.out.println(f1.getFileName());
}
}
}
public static void main(String[] args) throws IOException {
SmbjPoc smbjPoc = new SmbjPoc();
smbjPoc.connect();
smbjPoc.iterateDirectory();
smbjPoc.relaseResources();
}
}
Hi @abhisheksardana Your Code looks fine. but the issue sounds like https://github.com/hierynomus/smbj/issues/213 and check here also https://github.com/hierynomus/smbj/issues/254 Share name is the immediate folder name after the host name, //ipaddress/share_name/subfolders...
if you can access the share location in File Explorer then your code should work. also give SMB dialect version 2_1 or 3_1_1 with SMBJ 0.11.3.
Thanks, R Ramarajan.
It seems like the issues you mentioned are different. The issue we are facing is very specific to NFS shares. We will try with SMBJ 0.11.3. It would be good if you can share your use case - how you are using smbj to connect to NFS share. It might help us.
Hi @abhisheksardana
Sorry I too had same issue https://github.com/hierynomus/smbj/issues/619 I was answering with the impression you refer to NAS share.
please check the references it may help you and feel free to close the ticket. Thanks, R Ramarajan.
We are not trying to connect to NFS share directly using smbj instead we have a folder target inside DFS root which is pointing to NFS share. Ideally the library should follow the path seamlessly. It should not matter whether the underlying share is NFS or SMB.
@abhisheksardana - Did your issue get resolved?
@chidu106 - No, it's still there. Seems like it's the library limitation.
Hi @hierynomus, @pepijnve,
We have a DFS share root which internally is pointing to multiple shares and one of them is NFS share. We are getting below error when we are trying to list the NFS share (share.list("NFS_SHARE")). The path to the NFS share resolved successfully and it is trying to connect to the share via SMB_2_1 dialect and there it is failing.
This is how we are building the client: SmbConfig config = SmbConfig.builder().withDfsEnabled(true).build(); SMBClient client = new SMBClient(config);
Share hierarchy:
DFS_Share (\10.10.10.100\DFS) | - Normal_Share | - NFS_Share --> \10.10.10.101\NFS (Actual location of NFS share) | - DFS_Share_1
Exception in thread "main" com.hierynomus.mssmb2.SMBApiException: STATUS_BAD_NETWORK_NAME (0xc00000cc): Could not connect to \host\nfs at com.hierynomus.smbj.session.Session.connectTree(Session.java:180) at com.hierynomus.smbj.session.Session.connectShare(Session.java:151) at com.hierynomus.smbj.share.DiskShare.rerouteIfNeeded(DiskShare.java:91) at com.hierynomus.smbj.share.DiskShare.createFileAndResolve(DiskShare.java:100) at com.hierynomus.smbj.share.DiskShare.resolveAndCreateFile(DiskShare.java:79) at com.hierynomus.smbj.share.DiskShare.open(DiskShare.java:66) at com.hierynomus.smbj.share.DiskShare.openDirectory(DiskShare.java:130) at com.hierynomus.smbj.share.DiskShare.list(DiskShare.java:237) at com.hierynomus.smbj.share.DiskShare.list(DiskShare.java:210) at com.main.BasicEvaluation.iterateDirectory(BasicEvaluation.java:407) at com.main.BasicEvaluation.main(BasicEvaluation.java:532)
The same share can be accessed manually and via powershell as well so it seems like no issues with the share.