Reputation: 10014
I need to copy files from Samba share in my application. The paths are in smb://host/filename
format. How do I do it in nodejs? fs.createReadStream
refuses to open these paths. I need to do this on both Windows and *nix.
Upvotes: 6
Views: 8654
Reputation:
Assuming a Linux host (since you mentioned "samba" and not "MS SMB"), you'll first need to mount the remote server with smbmount
. This forum post has an overview of how to do that, then you just read the files as if they were local to your server.
Alternatively, smbget
lets you acquire single files without mounting the remote host, but isn't efficient for a large number of file requests.
Another edit; some example code:
var remoteFile = require('child_process').spawn('smbget', ['--stdout', 'smb://host/filename']);
remoteFile.stdout.on('data', function(chunk) {
//handle chunk of data
});
remoteFile.on('exit', function() {
//file loaded completely, continue doing stuff
});
Upvotes: 4