Subject: | Compensate for bad PASV response |
Some mis-configured FTP servers, not realizing that they are behind a
firewall, will send a non-routable address in response to the PASV
command. E.g.:
Net::FTP=GLOB(0x21582d8)>>> PASV
Net::FTP=GLOB(0x21582d8)<<< 227 Entering Passive Mode (10,0,0,253,126,206)
I request that Net::FTP be extended so as to compensate for such
incorrect responses.
I have altered the _dataconn method of my local copy of Net/FTP.pm as
follows:
+ my $peerAddr = join(".", @port[0 .. 3]);
+ if (
+ $port[0] == 10 or #
Class A unroutable
+ ($port[0] == 172 and $port[1] > 15 and $port[1] < 32) or #
Class B unroutable
+ ($port[0] == 192 and $port[1] == 168) ) { #
Class C unroutable
+ carp "Server sent us an unroutable address, $peerAddr, in the pasv
response. Use the server address instead.\n";
+ $peerAddr = ${*$ftp}{'net_ftp_host'};
+ }
$data = $pkg->new(
+ PeerAddr => $peerAddr,
- PeerAddr => join(".", @port[0 .. 3]),
PeerPort => $port[4] * 256 + $port[5],
LocalAddr => ${*$ftp}{'net_ftp_localaddr'},
Proto => 'tcp'
);
I offer it to the community under the same license as libnet.
Note that it assumes that any private address is unroutable, which is
true in my case. To be generally useful, it should probably be
controlled by a parameter in the constructor.