diff --git a/README.md b/README.md index 058ad0b..ded2fae 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,10 @@ Creates a new Ftp instance. Host name for the current FTP server. +#### Ftp.hostPasv + +Manual set host for passive mode. (When server return wrong host on passive mode. See issue https://github.com/sergi/jsftp/issues/158) + #### Ftp.port Port number for the current FTP server (defaults to 21). diff --git a/lib/jsftp.js b/lib/jsftp.js index cca2c63..6ba2ce4 100644 --- a/lib/jsftp.js +++ b/lib/jsftp.js @@ -53,6 +53,7 @@ function runCmd(name, ...params) { function Ftp(cfg) { this.host = cfg.host || FTP_HOST; + this.hostPasv = cfg.hostPasv; this.port = cfg.port || FTP_PORT; this.user = cfg.user || "anonymous"; this.pass = cfg.pass || "@anonymous"; @@ -241,6 +242,10 @@ Ftp.prototype.getPasvPort = function(text) { host = this.host; } + if (this.hostPasv) { + host = this.hostPasv; + } + return { host, port: (parseInt(match[2], 10) & 255) * 256 + (parseInt(match[3], 10) & 255)