Fix PASV address like lftp does (#349)

Some behind-firewall-and-corporate-network FTP servers
responds their private-net address instead of the
publicly reachable.

This fix checks for such address and uses the
command channel's address instead.
This commit is contained in:
Tamás Gulácsi
2023-11-13 20:56:59 +01:00
committed by GitHub
parent a58dc069db
commit e44fc64e60
2 changed files with 39 additions and 0 deletions

22
ftp_test.go Normal file
View File

@@ -0,0 +1,22 @@
package ftp
import (
"net"
"testing"
)
func TestBogusDataIP(t *testing.T) {
for _, tC := range []struct {
cmd, data net.IP
bogus bool
}{
{net.IPv4(192, 168, 1, 1), net.IPv4(192, 168, 1, 1), false},
{net.IPv4(192, 168, 1, 1), net.IPv4(1, 1, 1, 1), true},
{net.IPv4(10, 65, 1, 1), net.IPv4(1, 1, 1, 1), true},
{net.IPv4(10, 65, 25, 1), net.IPv4(10, 65, 8, 1), false},
} {
if got, want := isBogusDataIP(tC.cmd, tC.data), tC.bogus; got != want {
t.Errorf("%s,%s got %t, wanted %t", tC.cmd, tC.data, got, want)
}
}
}