I am trying to recursively check for a specific file in my company sharefolder using SmbFile
and NtlmPasswordAuthentication
.
As I am not very knowledgeable in Java I followed examples found in the internet but I keep getting the following error whenever I try to do a root.listFiles()
:
jcifs.smb.SmbException: Failed to connect: foldername/xx.xx.xx.xxx
jcifs.util.transport.TransportException
java.net.SocketException: Connection reset
I do have access rights to the sharefolder so my initial thought is that something is missing from my code but instead an authentication or proxy error. I am using the url in the following format: smb://foldername/something/somethingelse/anothersomething/
My code:
public static Boolean checkDiretory(String location, String docName){
Boolean result = false;
try {
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("", Consts.username, Consts.password);
SmbFile root = new SmbFile(location, auth);
List<SmbFile> files = Arrays.asList(root.listFiles());
for(SmbFile file : files){
if(file.isDirectory()){
result = checkDiretory(file.getPath(), docName);
if(result)
return result;
}
else{
if(file.exists() && file.getName().contains(docName)){
return true;
}else{
result = false;
}
}
}
} catch (SmbException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
return result;
}
Like Eliad Cohen suggested, you might have to change to SMBJ due to incompatibility of SMBv2 in jcifs.
I've found a similar issue here which may help you to solve this matter.
Keep in mind that the host is just your path!
Happy coding!