Permalink
Browse files

connection: add guards

  • Loading branch information...
1 parent fe96dde commit 007d1951d6021830b8e8e125060d30595f4593ea @mscdex committed Nov 12, 2013
Showing with 5 additions and 5 deletions.
  1. +5 −5 lib/connection.js
View
@@ -190,14 +190,14 @@ FTP.prototype.connect = function(options) {
function reentry(err, text, code) {
if (err && (!cmd || cmd === 'USER' || cmd === 'PASS' || cmd === 'TYPE')) {
self.emit('error', err);
- return self._socket.end();
+ return self._socket && self._socket.end();
}
if ((cmd === 'AUTH TLS' && code !== 234 && self.options.secure !== true)
|| (cmd === 'AUTH SSL' && code !== 334)
|| (cmd === 'PBSZ' && code !== 200)
|| (cmd === 'PROT' && code !== 200)) {
self.emit('error', makeError(code, 'Unable to secure connection(s)'));
- return self._socket.end();
+ return self._socket && self._socket.end();
}
if (!cmd) {
@@ -217,7 +217,7 @@ FTP.prototype.connect = function(options) {
// password required
if (!self.options.password) {
self.emit('error', makeError(code, 'Password required'));
- return self._socket.end();
+ return self._socket && self._socket.end();
}
cmd = 'PASS';
self._send('PASS ' + self.options.password, reentry, true);
@@ -302,7 +302,7 @@ FTP.prototype.connect = function(options) {
var timer = setTimeout(function() {
self.emit('error', new Error('Timeout while connecting to server'));
- self._socket.destroy();
+ self._socket && self._socket.destroy();
self._reset();
}, this.options.connTimeout);
@@ -696,7 +696,7 @@ FTP.prototype.mkdir = function(path, recursive, cb) { // MKD is optional
self._send('CWD ' + dirs[i], nextDir, true);
}, true);
}
- }
+ };
this.pwd(function(err, cwd) {
if (err)
return cb(err);

0 comments on commit 007d195

Please sign in to comment.