mscdex / node-ftp

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

Unable to parse PASV server response #93

Open aviynw opened 10 years ago

aviynw commented 10 years ago

I'm getting "Unable to parse PASV server response" when I try to run any command (get/put/list). Everything is running fine when I run a number of other ftp programs like filezilla.

Here is the output in my server log which is running proftp.

"IP ADDRESS" UNKNOWN - [15/Aug/2014:19:03:22 +0000] "USER userftp" 331 - "IP ADDRESS" UNKNOWN - [15/Aug/2014:19:03:22 +0000] "FEAT" - - "IP ADDRESS" UNKNOWN - [15/Aug/2014:19:03:22 +0000] "TYPE I" 200 - "IP ADDRESS" UNKNOWN - [15/Aug/2014:19:03:22 +0000] "TYPE A" 200 - "IP ADDRESS" UNKNOWN - [15/Aug/2014:19:03:22 +0000] "TYPE A" 200 - "IP ADDRESS" UNKNOWN - [15/Aug/2014:19:03:23 +0000] "PASV" 530 -

And here is my output for a successful connection from filezilla

"IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:12 +0000] "PASS (hidden)" 230 - "IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:13 +0000] "SYST" 215 - "IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:13 +0000] "FEAT" - - "IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:13 +0000] "PWD" 257 - "IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:13 +0000] "TYPE I" 200 - "IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:13 +0000] "PASV" 227 - "IP ADDRESS" UNKNOWN userftp [15/Aug/2014:19:03:13 +0000] "MLSD" 226 221

I'm not sure the best way to debug. Any help would be appreciated. Looking at the server logs it looks like it might not not be sending the password? There is no log for a "PWD" command like there is for the filezilla request.

Thanks.

mscdex commented 10 years ago

Can you show the code you're using and what proftpd version is this, just in case?

aviynw commented 10 years ago

Thanks for the quick reply! The proftp version is 1.3.5. I actually had it working yesterday, and am not sure what changed. But come to think of it, I had been using a precompiled binary package for proftp yesterday before deciding to compile it from source. I thought I tested it after compiling from source as well, but its possible I only tested it with filezilla and not with my node program. So maybe I'm just missing a necessary proftp module?

The modules I have are
mod_core.c mod_xfer.c mod_rlimit.c mod_auth_unix.c mod_auth_file.c mod_auth.c mod_ls.c mod_log.c mod_site.c mod_delay.c mod_facts.c mod_ident.c mod_auth_pam.c mod_deflate.c

I'm comparing them to whats listed here, http://www.proftpd.org/docs/modules/index.html , maybe there's something I need? The connection that filezilla successfully makes is also a passive one, so its not that my server can only make active connections which was one of my early thoughts.

Anyways, here is the relevant section from my code. The "_" object has all the appropriate properties. I logged them and quadruple checked.

.connection.on('ready', function() { .connection.list(function(e, list) { if (e) { throw e } else{ console.log('SUCESS! ' +list); } }); });

            _.connection.on('error', function(e) {
               throw e;
            });

            var obj={
                host: _.host,
                port: Number(_.port),
                user: _.user,
                password: _.password,
            };

            _.connection.connect(obj);

The exact Error is: ^ Error: Unable to parse PASV server response at Object.reentry as cb at Parser. (D:\workspace\listingsTest\node_modules\ftp\lib\connection.js:117:20) at Parser.emit (events.js:98:17) at Parser._write (D:\workspace\listingsTest\node_modules\ftp\lib\parser.js:58:10) at doWrite (_stream_writable.js:226:10) at writeOrBuffer (_stream_writable.js:216:5) at Parser.Writable.write (_stream_writable.js:183:11) at Socket.ondata (D:\workspace\listingsTest\node_modules\ftp\lib\connection.js:272:20) at Socket.emit (events.js:95:17) at Socket. (_streamreadable.js:748:14) at Socket.emit (events.js:92:17) at emitReadable (_stream_readable.js:410:10)

mscdex commented 10 years ago

Can you set debug: console.log in the object passed to connect() and post the output somewhere (be sure to remove/mask sensitive information)?

aviynw commented 10 years ago

Yes, here is the output. I haven't had a chance to see if playing with the proftp modules makes a difference. If it will help I can also set up a user for you to test on my server. Thanks.

DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'USER USERNAME_REMOVED' DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'FEAT' DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'TYPE I' DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'PASV' DEBUG: [connection] < '331 Password required for userftp\r\n'

mscdex commented 10 years ago

Can you try the master branch now?

aviynw commented 10 years ago

So, it now looks like its getting passed the authentication! But it still throws an error in the exact same place. The output is now

DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'USER USERNAME_REMOVED' DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'PASS PASSWORD REMOVED' DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'FEAT' DEBUG: [connection] < '220 you\'re at home\r\n' DEBUG: [parser] < '220 you\'re at home\r\n' DEBUG: [parser] Response: code=220, buffer='you\'re at home' DEBUG: [connection] > 'TYPE I' DEBUG: [connection] < '331 Password required forUSERNAME_REMOVED\r\n' DEBUG: [parser] < '331 Password required forUSERNAME_REMOVED\r\n' DEBUG: [parser] Response: code=331, buffer='Password required for USERNAME_REMOVED' DEBUG: [connection] > 'PASV' DEBUG: [connection] < '230 welcome !!!\r\n'

Error is: Error: Unable to parse PASV server response at Object.reentry as cb at Parser. (D:\workspace\listingsTest\node_modules\ftp\lib\connection.js:117:20) at Parser.emit (events.js:98:17) at Parser._write (D:\workspace\listingsTest\node_modules\ftp\lib\parser.js:58:10) at doWrite (_stream_writable.js:226:10) at writeOrBuffer (_stream_writable.js:216:5) at Parser.Writable.write (_stream_writable.js:183:11) at Socket.ondata (D:\workspace\listingsTest\node_modules\ftp\lib\connection.js:280:20) at Socket.emit (events.js:95:17) at Socket. (_stream_readable.js:748:14)

phishy commented 9 years ago

This client library also throws this same error while using npm ftpd as a server. Both these things would be great for testing and should totally work together. https://www.npmjs.com/package/ftpd

samkohli commented 9 years ago

Is this fixed? I am also getting this error....intermittently

mscdex commented 9 years ago

@samkohli Can you post your debug output?

mscdex commented 9 years ago

@phishy If you have have debug output, can you post it too?

Kadasiddha commented 7 years ago

Hi, I am also facing the same issue in the 'c.list' and 'c.put' methods. My code is given below:

    c.on('ready', function() {
        c.list('/monthly_stmt/',0,function(errftp,dataftp){

                  if (errftp){
                          console.log(errftp);
                  }
                  else{
                         console.log(dataftp);
                   }

           });
     });
     c.connect(config);

Error: Unable to parse PASV server response at Object.reentry [as cb] (/Users/kadasiddha/Documents/Documents/Backend/node_modules/ftp/lib/connection.js:857:19) at Parser. (/Users/kadasiddha/Documents/Documents/Backend/node_modules/ftp/lib/connection.js:117:20) at emitTwo (events.js:106:13) at Parser.emit (events.js:191:7) at Parser._write (/Users/kadasiddha/Documents/Documents/Backend/node_modules/ftp/lib/parser.js:59:10) at doWrite (_stream_writable.js:334:12) at writeOrBuffer (_stream_writable.js:320:5) at Parser.Writable.write (_stream_writable.js:247:11) at Socket.ondata (/Users/kadasiddha/Documents/Documents/Backend/node_modules/ftp/lib/connection.js:273:20) at emitOne (events.js:96:13)

wenlong-xyz commented 4 years ago

I met this issue today. For my case, its due to network ip.

Server log: 

39.106.123.123:41678-[testuser] Rejected data connection from foreign address 172.17.135.124:39686.

Client log: 

[Error] ftp disconnet!
[Error][uploadFtpAsync]   Error: Unable to parse PASV server response
    at Object.reentry [as cb] (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/connection.js:857:19)
    at Parser.<anonymous> (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/connection.js:117:20)
    at emitTwo (events.js:126:13)
    at Parser.emit (events.js:214:7)
    at Parser._write (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/parser.js:59:10)
    at doWrite (_stream_writable.js:396:12)
    at writeOrBuffer (_stream_writable.js:382:5)
    at Parser.Writable.write (_stream_writable.js:290:11)
    at Socket.ondata (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/connection.js:273:20)
    at emitOne (events.js:116:13)
Error: Unable to parse PASV server response
    at Object.reentry [as cb] (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/connection.js:857:19)
    at Parser.<anonymous> (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/connection.js:117:20)
    at emitTwo (events.js:126:13)
    at Parser.emit (events.js:214:7)
    at Parser._write (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/parser.js:59:10)
    at doWrite (_stream_writable.js:396:12)
    at writeOrBuffer (_stream_writable.js:382:5)
    at Parser.Writable.write (_stream_writable.js:290:11)
    at Socket.ondata (/usr/share/nginx/html/data-center-admin/node_modules/ftp/lib/connection.js:273:20)
    at emitOne (events.js:116:13)

39.106.123.123 is the public internet ip of ftp client machine and 172.17.135.124 is the local area network ip of ftp client machine. Ftp client and server are in the same local area network. I create the connetion using FTP server's public internet ip. And then transport data, received the above error, seems it's due to data trasporting using local area network ip. Connection ip is different to data transport ip. So rejected by server.

Fixed by changing connection ip to local area network ip.

TomlDev commented 3 years ago

I had the same issue when setting the host to localhost Fixed by using 127.0.0.1

ashuvax commented 2 years ago

It's like that with me too sometimes, is there a solution to this?

tsofist commented 2 years ago

It's like that with me too sometimes, is there a solution to this?

In my case, this problem occurred due to an attempt to transfer files in parallel (accidentally). Just don't do that :)

ashuvax commented 2 years ago

Indeed it happened to me because I transferred files at the same time There is no possibility to transfer files at the same time?

tsofist commented 2 years ago

Indeed it happened to me because I transferred files at the same time There is no possibility to transfer files at the same time?

Nope. But you can create multiple clients and share files for sending

ashuvax commented 2 years ago

Indeed it happened to me because I transferred files at the same time There is no possibility to transfer files at the same time?

Nope. But you can create multiple clients and share files for sending

Can you write an example please?

tsofist commented 2 years ago

Can you write an example please?

It all depends on your task. Such logic can be very complex depending on the capabilities of the server: someone allows many connections from one client, and someone restricts it. To implement complex logic, I would recommend switching to lftp - it takes on a lot of complexity.

https://lftp.yar.ru/features.html

eemailkrishna commented 4 days ago

image

if you are using internet with jio sim , then you will have to change your sim APN setting ,replace with www.google.com or JioNet