CIFS Network Mapping

104 views
Skip to first unread message

mememe

unread,
Aug 13, 2017, 6:48:38 PM8/13/17
to Node-RED
This maybe not a Node-Red question directly but maybe someone can think about how this can be done cleanly within Node-Red.

I want to read in a file from a network share.  And I want to dynamically create a link (with something like an EXEC node) to other PCs CIFS shares to get these files.

I've got a solution working but it's kinda messy and I worry about long term maintenance and unintentionally breaking something else.

For my setup I have Node-Red running in a Docker container.  I installed CIFS-UTILS inside the container and can map CIFS shares fine from the CLI.

For the EXEC node to work I had to:
- give the container SYS_ADMIN and DAC_READ_SEARCH priviliges
- give the node-red user a password
- add the node-red user to sudoers

My EXEC node command is:
echo <node-red password> | sudo -S mount -t cifs -o username=<CIFS username>,password=<CIFS password> //<IP>/<CIFS share> /usr/src/node-red/mount/<mount point> 

This all sounds like a bad idea but so far everything works fine.  And the mount only exists inside the container.  The Docker host can't see it.

I tried using the SMB2 npm package but it just kept giving me errors I didn't feel like tracking down.  It seems like that would have been a nice clean way to host the whole CIFS client inside a node so I wouldn't have to do anything with the host system.

My question is, Is there another way to get files from CIFS shares inside Node-Red?  It would be a handy node to have.



mememe

unread,
Aug 13, 2017, 10:35:44 PM8/13/17
to Node-RED
Never mind I got SMB2 to work.

Just install SMB2:

npm install smb2

Add smb2 to settings.js.

And then the function node looks like this:

// load the library 
var SMB2 = global.get('smb2');

// create an SMB2 instance 
var smb2Client = new SMB2({
  share:'\\\\myip\\mysharename',
  domain:'DESKTOP-A',
  username:'myusername',
  password:'mypassword'
});

smb2Client.readFile('path\\to\\document.txt', function(err, data){
    if(err) throw err;
    node.send({payload:data});
});

return;

Now I can load files from any Windows machine that has a shared folder.

Reply all
Reply to author
Forward
0 new messages