Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Copy files from Samba share in node.js

Copy files from Samba share in node.js


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.

Problem courtesy of:


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
Solution courtesy of: David Ellis


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Copy files from Samba share in node.js


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription