Node-SMB / marsaud-smb2

SMB2 Client
53 stars 46 forks source link

Multiple connections in same time #39

Open Zippersk opened 5 years ago

Zippersk commented 5 years ago

I have this code:

const smbClient = new SMB2({
  share: '\\\\127.0.0.1\\f',
  domain: 'WORKGROUP',
  username: 'user',
  password: 'pass'
});

function downloadFile (path, destination) {
  smbClient.createReadStream(path, function(err, readStream) {
    if (err) throw err;
    var writeStream = fs.createWriteStream(destination);
    readStream.pipe(writeStream);
  });
}

Then I want download two files:

downloadFile('file1.txt', 'f1.txt')
downloadFile('file2.txt', 'f2.txt')

But I get error: Uncaught Error: connect EISCONN 127.0.0.1:445 - Local (127.0.0.1:45618). When I comment one of the function call (or wait for first one to finish), everythings is fine. It seems that the client is creating new connection for every function call instead of use already created one.

PachVerb commented 4 years ago

i also found it, did you have resolve ?

Zippersk commented 4 years ago

No.

PachVerb commented 4 years ago

No.

The readme file of this tool mentions link management. Perhaps the timeout can be set to 0 when the constructor is initialized, which can solve the problem.

vdiez commented 3 years ago

You should check on your side not to execute the second downloadFile is not executed until the first one has finished, either by usse of the callback or by promisifing the calls and chaining them.

Otherwise you will need 2 different SMB connections