Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ type Config struct {
// hung connections.
DisableEPSV bool

// Ignores the returned remote host IP for PASV connections. Some FTP Servers are
// behind NAT, and return their internal IPs. This ignores the IP portion of the
// PASV response, using the control connection's IP instead.
IgnoreHost bool

// For testing convenience.
stubResponses map[string]stubResponse
}
Expand Down
14 changes: 14 additions & 0 deletions persistent_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,20 @@ func (pconn *persistentConn) prepareDataConn() (func() (net.Conn, error), error)
return nil, err
}

// Some FTP servers are behind NAT themselves, and lie about their IP address.
if pconn.config.IgnoreHost {
pconn.debug("Ignoring PASV returned host %s", host)
_, remotePort, err := net.SplitHostPort(host)
if err != nil {
return nil, err
}
remoteHost, _, err := net.SplitHostPort(pconn.host)
if err != nil {
return nil, err
}
host = net.JoinHostPort(remoteHost, remotePort)
}

pconn.debug("opening data connection to %s", host)
dc, netErr := net.DialTimeout("tcp", host, pconn.config.Timeout)

Expand Down