-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added minimal support for FTP with TLS/SSL #110
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
'use strict'; | ||
|
||
var Net = require('net'); | ||
var tls = require('tls'); | ||
var EventEmitter = require('events').EventEmitter; | ||
var es = require('event-stream'); | ||
var ResponseParser = require('ftp-response-parser'); | ||
|
@@ -117,13 +118,25 @@ Ftp.prototype._createSocket = function(port, host, firstAction) { | |
} | ||
|
||
this.authenticated = false; | ||
var socket = Net.createConnection(port, host, firstAction || NOOP); | ||
socket.on('connect', this.reemit('connect')); | ||
socket.on('timeout', this.reemit('timeout')); | ||
var self = this; | ||
var socket; | ||
|
||
this.pipeline = es.pipeline(socket, this.resParser); | ||
if(this.ssl){ | ||
socket = tls.connect(port,host,this.sslOptions,function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space after commas and |
||
//runt PROT command to specify that the data channel is secure | ||
self.runCommand('prot p',function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spaces again :) |
||
self.reemit('connect'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't really find any way of detecting timeouts with a tls connection actually |
||
}); | ||
} | ||
else{ | ||
socket = Net.createConnection(port, host, firstAction || NOOP); | ||
socket.on('connect', this.reemit('connect')); | ||
socket.on('timeout', this.reemit('timeout')); | ||
} | ||
|
||
var self = this; | ||
|
||
this.pipeline = es.pipeline(socket, this.resParser); | ||
this.pipeline.on('data', function(data) { | ||
self.emit('data', data); | ||
self.parseResponse.call(self, data); | ||
|
@@ -583,13 +596,22 @@ Ftp.prototype.pasvTimeout = function(socket, cb) { | |
Ftp.prototype.getPasvSocket = function(callback) { | ||
var timeout = this.timeout; | ||
callback = once(callback || NOOP); | ||
var self = this; | ||
this.execute('pasv', function(err, res) { | ||
if (err) return callback(err); | ||
|
||
getPasvPort(res.text, function(err, res) { | ||
if (err) return callback(err); | ||
|
||
var socket = Net.createConnection(res.port, res.host); | ||
var socket; | ||
if(self.ssl){ | ||
socket = tls.connect(res.port,res.host,self.sslOptions,function(){ | ||
self.reemit('connect'); | ||
}); | ||
} | ||
else{ | ||
socket = Net.createConnection(res.port, res.host); | ||
} | ||
socket.setTimeout(timeout || TIMEOUT); | ||
callback(null, socket); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space between
if
and(