spmjs / node-scp2

[MAINTAINER WANTED] A pure javascript scp program based on ssh2.
385 stars 96 forks source link

using scp2 in node-webkit #8

Open JackieLin opened 10 years ago

JackieLin commented 10 years ago

Hello: node-scp2 is a good tool to upload or download file from remote. When I use client.scp method in node-webkit, I meet a problem: first time the code run perfectly, but when I click the upload button to run this code again, it throw an exception. It refuse me. After I look over the scp2 source code, I found this in scp.jsfile:

async.eachSeries(files, function(fpath, done) {
  fs.stat(fpath, function(err, stats) {
    if (err) {
      done(err);
      return;
    }
    if (stats.isFile()) {
      var fname = path.relative(rootdir, fpath);
      client.upload(
        fpath, path.join(client.remote.path, fname), done
      );
    } else {
      done();
    }
  });
}, function(err) {
  // never forget to close the session close by myself
  client.on('close', function() {
    callback(err);
  });
  client.close();
});

This problem is because that after client.scp method, it close the connection automatically, so next time when I run this method, the code throw an error!

I suggest that whether client.scp method can add a parameter like autoclose: false?? so user can choose whether the connection should be closed or not.

Thanks!!

kjerniga commented 10 years ago

I'm facing the same issue. Retries work if I comment out the client.close(), but I think the connection over time will eventually drop. If I let it close completely, and retry I get:

path.js:299 return splitPathRe.exec(filename).slice(1); ^ RangeError: Maximum call stack size exceeded

Anyone figured out how to do a retry successfully?

kjerniga commented 10 years ago

I just created a new instance of the client for the retry and it works.