No announcement yet.

UNC Access to read file

  • Filter
  • Time
  • Show
Clear All
new posts

  • UNC Access to read file

    Dear all,

    Wondering if anyone can help. I am running 2.2.1 on CentOS 6 and one of the channels is required to pick up a PDF file in the transformation and add it to a channelMap variable.

    for example:

    var encodedPDFfile = "";
    var contents = FileUtil.readBytes("\\\\DOMAIN/USER:[email protected]\\FACT\\RISS Electronic Reports\\RISS-Report-5QG-20130302084731.pdf");
    encodedPDFfile = FileUtil.encode(contents);
    Problem is this does not work - Is it possible to pass a domain login and password in this way? How can I pick up the file on the remote server and specify username and password?


  • #2
    What you have there should be working but depending on where you are trying to access the variable it may not be available. Can be specific as to what you are trying to do?


    • #3
      The code to pick up the pdf file is in a javascript message transformer step. The intention is to send it out as an email attachment.

      I have tried installing Mirth Connect on the same windows server that the file exists, and used a short UNC path:

      var contents = FileUtil.readBytes("\\\\H-PATHFACT\\FACT\\RISS Electronic Reports\\RISS-Report-5QG-20130302084731.pdf");
      and the file is picked up just fine.

      When I use the Mirth Connect installed on the Linux server, trying to pick up the file on the windows server (and supplying the local or domain username and password that has rights to the folder) it fails with error:

      Code: \\H-PATHFACT/user:[email protected]\FACT\testingmirth.txt (No such file or directory)
      I am wondering if it is something to do with the syntax of the username [email protected]:
      H-PATHFACT/localuser:[email protected]
      DOMAIN/domainuser:[email protected]
      (where H-PATHFACT is the hostname of the server)


      • #4
        We have ran into this problem doing FTPs. The issue that we had, although we were pulling it from the Mirth folder structure, was that we were not coming in at the same folder level as we thought. Verify that when you connect to the Windows server you are at the correct folder level.


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

          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 =;
          			var encodedFile = FileUtil.encode(bytes);
          	} catch(e) {
          		logger.error("Unable to connect: smb read failed for share:  smb://" + share + " filename: " + filename);
          	return encodedFile;
          Last edited by seaston; 03-14-2013, 11:36 PM.


          • #6
            How can I use smb in Javascript Reader (Source tab) to read a file from other pc?


            This is my requirement.

            Source - > javascript reader

            I get information from the database.

            I want to use that information and want to read a file from other machine with "smb".

            Destination -> SFTP

            I want to upload the file on SFTP

            and in POstProcessor script, I want to update the database (ie. IsUploaded='Y') for that file.

            Any help will be appreciated.

            Vijay Panchal
            WTI, India