OiRc
OiRc

Reputation: 1622

connect ECONNREFUSED 127.0.0.1:21 error in node js

I'm writing a simple application in node js, and i'm having this problem:

Error: connect ECONNREFUSED 127.0.0.1:21
    at Object.exports._errnoException (util.js:1034:11)
    at exports._exceptionWithHostPort (util.js:1057:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1099:14)

This is the script:

var Client = require('ftp');
var fs = require('fs');


  var c = new Client();
  c.on('ready', function() {
    c.get('/foo/foo1.txt', function(err, stream) {
      if (err) throw err;
      stream.once('close', function() { c.end(); });
      stream.pipe(fs.createWriteStream('foo.local-copy.txt'));
    });
  });
  c.connect('MYIP',21,false,'none','user','password',10000,10000,10000);

  c.end();

what's wrong?

Upvotes: 2

Views: 4970

Answers (2)

Prog_kriss
Prog_kriss

Reputation: 31

The documentation said use an object in the connection parameters.

try this:

var Client = require('ftp');
var fs = require('fs');
var c = new Client();
c.on('ready', function() {
    c.list(function(err, list) {
        if (err) throw err;
        console.dir(list);
        c.end();
    });
    c.put('foo.txt', 'foo.remote-tesssstt.txt', function(err) {
        if (err) throw err;
        c.end();
    });
});
// connect to localhost:21 as anonymous
c.connect({
    host: 'your_host', // ex: files.000webhost.com
    port: 21,
    user: 'your_user',
    password: 'your_password',
    secure: false,
    secureOptions: 'none',
    connTimeout: 10000,
    pasvTimeout: 10000,
    aliveTimeout: 10000
});

Upvotes: 0

Quentin
Quentin

Reputation: 944005

It says the connection to port 21 was refused.

The most likely reason for this is that you aren't running an FTP server that is listening on that port.

You might also have firewalled it off (although that's unlikely on the loopback interface).

Upvotes: 3

Related Questions