Skip to content
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

add i18n support #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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;
Expand Down