List File Shares and report disk usage

Nov 16 2015

List File Shares and report disk usage

Posted by AJ Mercer at 1:47 pm CFML | ColdFusion | Java | Lucee

With some assistance of Denny the Java/CFML Guru, here is some code for getting a list of file shares for a given server, then get toal and fee space using Java library jcifs.smb.SmbFile

servername = "<server>";
smbAuth = CreateObject('java','jcifs.smb.NtlmPasswordAuthentication').init("<domain>", "<username>", "<password>");
dump(var=smbAuth.hashCode(), label='#smbAuth.toString()#');
dump(var=smbAuth, label='#smbAuth.toString()#');

jcifs = CreateObject('java','jcifs.smb.SmbFile').init('smb://#servername#/', smbAuth);
shares = [];
ok = createObject("java", " java.util.Collections").addAll(shares, jcifs.list()); // member function does not like Native Array (java.lang.String[])
    jcifsShare = CreateObject('java','jcifs.smb.SmbFile').init('smb://#servername#/#element#', smbAuth);

    dump(var=jcifsShare.length(), label="total space [bytes]");
    dump(var=jcifsShare.getDiskFreeSpace(), label="free space [bytes]");