Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix secure data connections

also, not all servers are set up to allow no TLS session re-use, so re-use the existing session for secure data connections
commit 7b7b02432be2cbaad359039dbc7c3bc3b4d28b84 1 parent 9989831
@mscdex authored
Showing with 13 additions and 12 deletions.
  1. +13 −12 lib/ftp.js
View
25 lib/ftp.js
@@ -803,28 +803,29 @@ FTP.prototype._pasv = function(cb) {
FTP.prototype._pasvConnect = function(ip, port, cb) {
var self = this,
- socket = new Socket(), ssocket,
+ socket = new Socket(),
sockerr,
timedOut = false,
timer = setTimeout(function() {
timedOut = true;
- ssocket.destroy();
+ socket.destroy();
cb(new Error('Timed out while making data connection'));
}, this.options.pasvTimeout);
socket.setTimeout(0);
- if (self.options.secure === true)
- ssocket = tls.connect({ socket: socket }, onconnect);
- else {
- socket.once('connect', onconnect);
- ssocket = socket;
- }
- function onconnect() {
+ socket.once('connect', function() {
+ if (self.options.secure === true) {
+ socket = tls.connect({
+ socket: socket,
+ session: self._socket.getSession() // re-use existing session
+ });
+ socket.setTimeout(0);
+ }
clearTimeout(timer);
- self._pasvSocket = ssocket;
- cb(undefined, ssocket);
- };
+ self._pasvSocket = socket;
+ cb(undefined, socket);
+ });
socket.once('error', function(err) {
sockerr = err;
});
Please sign in to comment.
Something went wrong with that request. Please try again.