web stats
Mirth Community - View Single Post - UNC Access to read file
View Single Post
  #5  
Old 03-15-2013, 12:18 AM
seaston seaston is offline
OBX.3 Kenobi
 
Join Date: Feb 2010
Location: London, UK
Posts: 168
seaston is on a distinguished road
Default

I found that this function seemed to do the trick (using smb):

Code:
function smbReadBytes(share,username,password,timeout,directory,filename) {
	// share like "hostname/SHARE"
	// username like "DOMAIN/user"
	// directory like SHARE
	// filename like testingmirth.pdf
	var encodedFile = "";

	try {
		var readit = true;
		var smbConn = new com.mirth.connect.connectors.file.filesystems.SmbFileConnection(share,username,password,timeout);
		// check it can read from the share:
		if (!smbConn.canRead("")) {
			//throw "Cannot read from smb share " + share; 
			logger.error("Cannot read from smb share " + share);
			readit = false;
		}
		// check it can read the file:
		if (!smbConn.exists(filename,directory)) {
			//throw "Cannot read file from smb: " + filename; 
			logger.error("Cannot read file from smb://" + share + " filename: " + filename);
			readit = false;
		}
		if (readit) {
			var inputStream = smbConn.readFile(filename,directory);
			var bytes = org.apache.commons.io.IOUtils.toByteArray(inputStream);
			var encodedFile = FileUtil.encode(bytes);
			inputStream.close();
		}
	} catch(e) {
		logger.error("Unable to connect: smb read failed for share:  smb://" + share + " filename: " + filename);
	}

	return encodedFile;
}
Simon

Last edited by seaston; 03-15-2013 at 12:36 AM.
Reply With Quote