mscdex / node-ftp

An FTP client module for node.js
MIT License
1.13k stars 243 forks source link

425 Cannot open data connection #65

Open myoung69 opened 11 years ago

myoung69 commented 11 years ago

does the following mean i am trying to use too many data connections at once?

I randomly get this error when listing all the directories on a ftp server before i try to retrieve any files.

if it is too many connections is the a max connection setting somewhere that i am missing?

{ name: 'button-l.png', type: '-', size: 329, date: Fri Oct 18 2013 05:52:00 GMT-0400 (EDT), path: '/www/images/button' }, { name: 'button-r.png', type: '-', size: 343, date: Fri Oct 18 2013 05:52:00 GMT-0400 (EDT), path: '/www/images/button' } ] [connection] < '150 Opening BINARY mode data connection.\r\n425 Cannot open data connection.\r\n' [parser] < '150 Opening BINARY mode data connection.\r\n' [parser] Response: code=150, buffer='Opening BINARY mode data connection.' [parser] < '425 Cannot open data connection.\r\n' [parser] Response: code=425, buffer='Cannot open data connection.' { [Error: Cannot open data connection.] code: 425 }

mscdex commented 11 years ago

What does your code look like?

EDIT: Also, when entering PASV mode, is the IP given by the server in its PASV response correct?

myoung69 commented 11 years ago

The IP in PASV line is correct.

The code i am using is below. Please forgive the bad coding i am still learning how to do this.

And as always thank you for whatever help you can give me.

var Client = require('ftp'),
    connects = 0,
    filelist = [];

var srcparams = { // windows FTP Server
    host: "ftptest1.com",
    port: 21,
    user: "ftp",
    password: "password"
};

var destparams = {
    host: "ftptest2.com",
    port: 21,
    user: "ftp",
    password: "password"
};

var src = new Client();

var dest = new Client();

src.on('ready', function() {
    console.log('source ready');
    connects++;
    list();
});

dest.on('ready', function() {
    console.log('destination ready');
    connects++;
    list();
});

src.connect(srcparams);
dest.connect(srcparams);

function DirWalk(dir, prefix, callback) {
    var directory;
    if (prefix !== undefined || prefix !== '') {
        directory = prefix + '/' + dir;
    } else {
        directory = dir;
    }
    src.list(directory, function(err, dirlist) {
        if (err) {
            console.log(err);
        }
        callback(null, directory, dirlist);
    });
}

function toDirList(files, prefix) {
    if (prefix === undefined) {
        prefix = '';
    }
    for (var b in files) {
        files[b].path = prefix;
        filelist.push(files[b]);
        if (files[b].type === 'd') { // is a directory
            files[b].path = prefix;
            DirWalk(files[b].name, prefix, function(err, prefix, dirlist) {
                if (dirlist.length > 0) {
                    toDirList(dirlist, prefix);
                }
            });
        } else if (files[b].type === '-') {

        }
    //console.log(filelist);
    }
}

function list() {
    if (connects === 2) {
        src.list(function(err, list) {
            toDirList(list);
        });
    }
}
myoung69 commented 11 years ago

Yes the IP is correct in this line. [connection] < '227 Entering Passive Mode (192,96,210,12,8,127).\r\n'

mscdex commented 10 years ago

What if you limit calling DirWalk so that instead of the for-loop, it's only called again once the callback is called?