Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 8, 2025

Some FTP servers return 0,0,0,0 in PASV responses when they cannot determine their own IP address. This fix ensures the FTP client uses the connection IP address instead of the unusable 0,0,0,0.

Problem

When FTP servers can't guess their IP address, they may return 0,0,0,0 in PASV responses like:

227 Entering Passive Mode (0,0,0,0,20,21).

Previously, the client would attempt to connect to 0.0.0.0 for data connections, which would fail since it's not a valid destination address.

Solution

Enhanced the isBogusDataIP function to explicitly detect unspecified IP addresses (0.0.0.0 for IPv4, :: for IPv6) and treat them as bogus. When a bogus IP is detected, the client now uses the control connection's IP address for data connections instead.

func isBogusDataIP(cmdIP, dataIP net.IP) bool {
    return dataIP.IsMulticast() ||
        dataIP.IsUnspecified() || // Explicitly handle 0.0.0.0 and ::
        cmdIP.IsPrivate() != dataIP.IsPrivate() ||
        cmdIP.IsLoopback() != dataIP.IsLoopback()
}

Testing

Added comprehensive tests covering:

  • Unit tests for the bogus IP detection logic with various IP combinations
  • Integration test demonstrating end-to-end PASV functionality with 0,0,0,0 responses
  • Verification that existing functionality remains unchanged

All existing tests (40 total) continue to pass, ensuring no regressions were introduced.

Impact

This change improves compatibility with FTP servers that have networking configuration issues or are behind NAT/firewalls where they cannot determine their external IP address. The fix is minimal and surgical, adding only explicit handling for unspecified addresses without changing the existing logic flow.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: cursedcoder <899452+cursedcoder@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] I need to tweak PASV, so if for some reason the ftp server can't guess it's ip, we will be reusing the one we have instead of 0,0,0,0 Fix PASV command to handle servers returning 0,0,0,0 IP address Sep 8, 2025
@Copilot Copilot AI requested a review from cursedcoder September 8, 2025 00:35
Copilot finished work on behalf of cursedcoder September 8, 2025 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants