Permalink
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
1 parent 9989831 commit 7b7b02432be2cbaad359039dbc7c3bc3b4d28b84 @mscdex committed Dec 18, 2012
Showing with 13 additions and 12 deletions.
  1. +13 −12 lib/ftp.js
View
@@ -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;
});

0 comments on commit 7b7b024

Please sign in to comment.