From da089bfca92850ec96588365cf2addf9b210bddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauris=20V=C4=81vere?= Date: Sat, 1 Aug 2015 14:35:31 +0300 Subject: [PATCH] add i18n support https://wiki.filezilla-project.org/Character_Set Conflicting specification --- lib/connection.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 94fcae0..4a6a30f 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -65,6 +65,7 @@ var FTP = module.exports = function() { this._keepalive = undefined; this._ending = false; this._parser = undefined; + this._utf8 = false; this.options = { host: undefined, port: undefined, @@ -230,8 +231,20 @@ FTP.prototype.connect = function(options) { cmd = 'FEAT'; self._send(cmd, reentry, true); } else if (cmd === 'FEAT') { - if (!err) + if (!err) { self._feat = Parser.parseFeat(text); + self._utf8 = self._feat.indexOf('UTF8')>=0 // RFC #2640 + } + if (self._utf8) { + // required by MS IIS 7.x FTP implementation which think based on + // http://tools.ietf.org/html/draft-ietf-ftpext-utf-8-option-00 + cmd = 'OPTS'; + self._send('OPTS UTF8 ON', reentry, true); + } else { + cmd = 'TYPE'; + self._send('TYPE I', reentry, true); + } + } else if (cmd === 'OPTS') { // ignore OPTS UTF8 result cmd = 'TYPE'; self._send('TYPE I', reentry, true); } else if (cmd === 'TYPE') @@ -438,7 +451,9 @@ FTP.prototype.list = function(path, zcomp, cb) { sock.pipe(source); } - source.on('data', function(chunk) { buffer += chunk.toString('binary'); }); + source.on('data', function(chunk) { + buffer += chunk.toString(self._utf8 ? 'utf8' : 'binary'); + }); source.once('error', function(err) { if (!sock.aborting) sockerr = err;