Giter VIP home page Giter VIP logo

Comments (14)

mscdex avatar mscdex commented on June 26, 2024 1

What if you instead just change the line

stream.setEncoding('utf8');

to

stream.setEncoding('binary');

?

from node-ftp.

atian25 avatar atian25 commented on June 26, 2024

no, that don't work. output : âÊÔ.md when file name is 测试.md
nodejs is not support gbk now, so we need modules like iconv / iconv-lite

from node-ftp.

ggd543 avatar ggd543 commented on June 26, 2024

I have the same issue

from node-ftp.

ramstein74 avatar ramstein74 commented on June 26, 2024

stream.setEncoding('binary');
^
TypeError: Cannot call method 'setEncoding' of undefined
at FTP._pasvGetLines (C:\CroNode\node_modules\ftp\ftp.js:508:12)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
[Finished in 0.4s with exit code 1]

from node-ftp.

ramstein74 avatar ramstein74 commented on June 26, 2024

changing ftp.js encoding to utf8 the error is the same.
I was testing conn.get '1.txt'

from node-ftp.

mscdex avatar mscdex commented on June 26, 2024

@ramstein74 With the original code from master, can you set debug: console.log in the constructor options and post the output somewhere? I'm very interested in finding out what's causing this....

from node-ftp.

ramstein74 avatar ramstein74 commented on June 26, 2024

i solved this problem.
I did not have auth to download a file from ftp server.
Next error

i saw with node inspector

The console error is ftp_test.js:35
Server error:425 Unable to open the data connection

in node monitor (web) tracing stops at this file
Timers.JS

line 109

debug(msecs + ' list empty');
assert(L.isEmpty(list));
list.close();
delete lists[msecs];
};here exists!!!!!!!!!!!!!
}

My app is in coffee so i converted it to javascript (code below)

(function() {
var FTPClient, conn;

FTPClient = require("ftp");

conn = new FTPClient();

conn.on("connect", function() {
return conn.auth(function(e) {
if (e) {
throw e;
}
conn.cwd('\ftproot\memcard', function() {
return conn.pwd(function(e, dir) {
if (e) {
throw e;
}
return console.log(dir);
});
});
conn.get('1.txt', function(e, st) {
if (e) {
throw e;
}
st.on('success', function() {
return console.log("file received ok");
});
return st.on('error', function() {
return console.log("erro in file");
});
});
return conn.list(function(e, entries) {
var i, len;
if (e) {
throw e; This is line 35!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ( if i remove the get file code, the listing goes ok)
}
console.log("");
i = 0;
len = entries.length;
console.log(len);
while (i < len) {
if (typeof entries[i] !== "string") {
if (entries[i].type === "l") {
entries[i].type = "LINK";
} else if (entries[i].type === "-") {
entries[i].type = "FILE";
} else {
if (entries[i].type === "d") {
entries[i].type = "DIR";
}
}
console.log(" " + entries[i].type + " " + entries[i].size + " " + entries[i].date + " " + entries[i].name);
}
++i;
}
console.log("");
return conn.end();
});
});
});

conn.connect();

}).call(this);

from node-ftp.

mscdex avatar mscdex commented on June 26, 2024

Please try with the master branch now if you can and let me know how it goes. All file names should be 'binary' strings.

from node-ftp.

lizhipower avatar lizhipower commented on June 26, 2024

i can get the file lists from the ftp, and with iconv.decode(list.name, 'gbk') I can get the correct Chinese, but the problem is how can I get the specified file lists of a folder in Chinese, like ‘/测试’
i can't the file lists with
ftpClient.list( ‘/测试’, (e, list1) => { if (e) throw e; console.log(list1); });
but it;s ok with
ftpClient.list( ‘/test’, (e, list1) => { if (e) throw e; console.log(list1); });

from node-ftp.

lfcgomes avatar lfcgomes commented on June 26, 2024

@lizhipower any advance on this? How did you solve this? I'm facing the same issue here.

from node-ftp.

lizhipower avatar lizhipower commented on June 26, 2024

from node-ftp.

likev avatar likev commented on June 26, 2024

@mscdex you should use Buffer with filepath, or add a encode option with method such as list, cwd etc.

FTP.prototype.cwd = function (path, cb, promote) {
    let cmddata = 'CWD ';
    if (Buffer.isBuffer(path)) cmddata = Buffer.concat([Buffer.from(cmddata), path]);
     else cmddata += path;

    this._send(cmddata, function (err, text, code) {
        if (err)
        return cb(err);
        var m = RE_WD.exec(text);
        cb(undefined, m ? m[1] : undefined);
    }, promote);
};
FTP.prototype._send = function (cmd, cb, promote) {
    clearTimeout(this._keepalive);
    if (cmd !== undefined) {
        if (promote)
        this._queue.unshift({
            cmd: cmd,
            cb: cb
        });
         else
        this._queue.push({
            cmd: cmd,
            cb: cb
        });
    }
    var queueLen = this._queue.length;
    if (!this._curReq && queueLen && this._socket && this._socket.readable) {
        this._curReq = this._queue.shift();
        if (this._curReq.cmd === 'ABOR' && this._pasvSocket)
        this._pasvSocket.aborting = true;
        this._debug && this._debug('[connection] > ' + inspect(this._curReq.cmd));
        
        let cmddata = this._curReq.cmd;
        if (Buffer.isBuffer(cmddata)) cmddata = Buffer.concat([cmddata, Buffer.from('\r\n')]);
         else cmddata += '\r\n';
        this._socket.write(cmddata);
    } else if (!this._curReq && !queueLen && this._ending)
    this._reset();
};

from node-ftp.

iamlion avatar iamlion commented on June 26, 2024

i can get the file lists from the ftp, and with iconv.decode(list.name, 'gbk') I can get the correct Chinese, but the problem is how can I get the specified file lists of a folder in Chinese, like ‘/测试’
i can't the file lists with
ftpClient.list( ‘/测试’, (e, list1) => { if (e) throw e; console.log(list1); });
but it;s ok with
ftpClient.list( ‘/test’, (e, list1) => { if (e) throw e; console.log(list1); });

how to resolve it?

from node-ftp.

iamlion avatar iamlion commented on June 26, 2024

i can get the file lists from the ftp, and with iconv.decode(list.name, 'gbk') I can get the correct Chinese, but the problem is how can I get the specified file lists of a folder in Chinese, like ‘/测试’
i can't the file lists with
ftpClient.list( ‘/测试’, (e, list1) => { if (e) throw e; console.log(list1); });
but it;s ok with
ftpClient.list( ‘/test’, (e, list1) => { if (e) throw e; console.log(list1); });

I resolve it , You need convert 'cmd' to 'GBK'.

var iconv = require("../../iconv-lite");

FTP.prototype._send = function(cmd, cb, promote) {
  clearTimeout(this._keepalive);
  if (cmd !== undefined) {
    if (promote)
      this._queue.unshift({ cmd: cmd, cb: cb });
    else
      this._queue.push({ cmd: cmd, cb: cb });
  }
  var queueLen = this._queue.length;
  if (!this._curReq && queueLen && this._socket && this._socket.readable) {
    this._curReq = this._queue.shift();
    if (this._curReq.cmd === 'ABOR' && this._pasvSocket)
      this._pasvSocket.aborting = true;
    this._debug&&this._debug('[connection] > ' + inspect(this._curReq.cmd));

    let cmd = this._curReq.cmd + '\r\n';
    let buf = iconv.encode(cmd, 'gbk');
    this._socket.write(buf);
  } else if (!this._curReq && !queueLen && this._ending)
    this._reset();
};

from node-ftp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.