spmjs / node-scp2

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

fix(client): release underlining resourse #16

Closed xujihui1985 closed 9 years ago

xujihui1985 commented 9 years ago
  1. set underlining resource sftp and ssh to null after close the client otherwise there will be error when I scp with same client second time
  2. removeListener after client closed; eg: if I want to reuse client muliple times there will be problem async.each([folders], function(folder, next) { client.scp(folder, dest, function() { next(); }) }, function done() {

})

in this demo, the next callback will be called twice thus done will be called twice

xujihui1985 commented 9 years ago
 if (this.__sftp) {
    callback(null, this.__sftp);
    return;
  }

  var remote = _.defaults(this.remote, this._options);
  if (this.__ssh) {
    this.__ssh.connect(remote);
    return;
  }

when I try to call client.scp second time, it complain that then connection has already close, that's because this.ssh has closed but the reference is still there, so when it check `this.sftp` it return true and returned immediatly

I thought, it's better to set the two underlining object to null after closed, so it will create a new client then.