Skip to content

Commit 6ae56c4

Browse files
committed
add i18n support
mscdex#123 Thanks @vavere
1 parent 7dff82f commit 6ae56c4

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

lib/connection.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ var FTP = module.exports = function() {
6666
this._keepalive = undefined;
6767
this._ending = false;
6868
this._parser = undefined;
69+
this._utf8 = false;
6970
this.options = {
7071
host: undefined,
7172
port: undefined,
@@ -234,8 +235,20 @@ FTP.prototype.connect = function(options) {
234235
cmd = 'FEAT';
235236
self._send(cmd, reentry, true);
236237
} else if (cmd === 'FEAT') {
237-
if (!err)
238+
if (!err) {
238239
self._feat = Parser.parseFeat(text);
240+
self._utf8 = self._feat.indexOf('UTF8')>=0 // RFC #2640
241+
}
242+
if (self._utf8) {
243+
// required by MS IIS 7.x FTP implementation which think based on
244+
// http://tools.ietf.org/html/draft-ietf-ftpext-utf-8-option-00
245+
cmd = 'OPTS';
246+
self._send('OPTS UTF8 ON', reentry, true);
247+
} else {
248+
cmd = 'TYPE';
249+
self._send('TYPE I', reentry, true);
250+
}
251+
} else if (cmd === 'OPTS') { // ignore OPTS UTF8 result
239252
cmd = 'TYPE';
240253
self._send('TYPE I', reentry, true);
241254
} else if (cmd === 'TYPE')
@@ -444,7 +457,7 @@ FTP.prototype.list = function(path, zcomp, cb) {
444457
}
445458

446459
source.on('data', function(chunk) {
447-
buffer += decoder.write(chunk);
460+
buffer += chunk.toString(self._utf8 ? 'utf8' : 'binary');
448461
});
449462
source.once('error', function(err) {
450463
if (!sock.aborting)
@@ -743,12 +756,12 @@ FTP.prototype.rmdir = function(path, recursive, cb) { // RMD is optional
743756
if (!recursive) {
744757
return this._send('RMD ' + path, cb);
745758
}
746-
759+
747760
var self = this;
748761
this.list(path, function(err, list) {
749762
if (err) return cb(err);
750763
var idx = 0;
751-
764+
752765
// this function will be called once per listing entry
753766
var deleteNextEntry;
754767
deleteNextEntry = function(err) {
@@ -760,9 +773,9 @@ FTP.prototype.rmdir = function(path, recursive, cb) { // RMD is optional
760773
return self.rmdir(path, cb);
761774
}
762775
}
763-
776+
764777
var entry = list[idx++];
765-
778+
766779
// get the path to the file
767780
var subpath = null;
768781
if (entry.name[0] === '/') {
@@ -776,7 +789,7 @@ FTP.prototype.rmdir = function(path, recursive, cb) { // RMD is optional
776789
subpath = path + '/' + entry.name
777790
}
778791
}
779-
792+
780793
// delete the entry (recursively) according to its type
781794
if (entry.type === 'd') {
782795
if (entry.name === "." || entry.name === "..") {

0 commit comments

Comments
 (0)