Skip to content

Instantly share code, notes, and snippets.

@benktesh
Created November 20, 2019 21:49
Show Gist options
  • Save benktesh/ada23c7e6039925d5cf20fbc62281b64 to your computer and use it in GitHub Desktop.
Save benktesh/ada23c7e6039925d5cf20fbc62281b64 to your computer and use it in GitHub Desktop.
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;
import java.net.MalformedURLException;
public class Main {
public static void main(String[] args) {
String url = "smb://127.0.0.1/test/";
String userName = "test";
String password = "password";
String domain = null;
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, userName, password);
try {
doRecursiveLookup(new SmbFile(url, auth));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
/*
* Recursively scans through the folder for files and prints the name of folder and file
*/
public static void doRecursiveLookup(SmbFile smb) {
try {
if (smb.isDirectory()) {
System.out.println(smb.getName());
for (SmbFile f : smb.listFiles()) {
if (f.isDirectory()) {
doRecursiveLookup(f);
} else {
System.out.println("\t:" + f.getName());
}
}
} else {
System.out.println("\t:" + smb.getName());
}
} catch (SmbException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment