简体   繁体   中英

Nodejs - catch upload to ftp error(ftp module)

How can I catch an upload error in node js via ftp? For example when my computer loses the connection. I am using ftp module and nothing of this(error, close or end) throws any errors. Or may be there are any other solutions, i mean another npm module?

var Client = require('ftp');
var c = new Client();

c.on('ready', callback);
c.on('error', function(err){
    console.log(err);
});
c.on('close', function(err){
    console.log(err);
});
c.on('end', function(){
    console.log("END");
});

c.connect({
    host: host,
    port: port,
    user: username,
    password: password
});
...
c.put(uploadfile, uploadpath, onupload);

I know that this is not the best idea to edit the library, but i solved my problem by adding this code

    if(err.indexOf("ECONNRESET") > -1){
        this._reset();
    }

after

sock.once('error', function(err) {
    self.emit('error', err);

on 965 line in connection.js of ftp library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM