protected void _parsePassiveModeReply()

in src/main/java/org/apache/commons/net/ftp/FTPClient.java [824:862]


    protected void _parsePassiveModeReply(final String reply) throws MalformedServerReplyException {
        final Matcher m = PARMS_PAT.matcher(reply);
        if (!m.find()) {
            throw new MalformedServerReplyException("Could not parse passive host information.\nServer Reply: " + reply);
        }

        int pasvPort;
        // Fix up to look like IP address
        String pasvHost = "0,0,0,0".equals(m.group(1)) ? _socket_.getInetAddress().getHostAddress() : m.group(1).replace(',', '.');

        try {
            final int oct1 = Integer.parseInt(m.group(2));
            final int oct2 = Integer.parseInt(m.group(3));
            pasvPort = (oct1 << 8) | oct2;
        } catch (final NumberFormatException e) {
            throw new MalformedServerReplyException("Could not parse passive port information.\nServer Reply: " + reply);
        }

        if (isIpAddressFromPasvResponse()) {
            // Pre-3.9.0 behavior
            if (passiveNatWorkaroundStrategy != null) {
                try {
                    final String newPassiveHost = passiveNatWorkaroundStrategy.resolve(pasvHost);
                    if (!pasvHost.equals(newPassiveHost)) {
                        fireReplyReceived(0, "[Replacing PASV mode reply address " + this.passiveHost + " with " + newPassiveHost + "]\n");
                        pasvHost = newPassiveHost;
                    }
                } catch (final UnknownHostException e) { // Should not happen as we are passing in an IP address
                    throw new MalformedServerReplyException("Could not parse passive host information.\nServer Reply: " + reply);
                }
            }
        } else if (_socket_ == null) {
            pasvHost = null; // For unit testing.
        } else {
            pasvHost = _socket_.getInetAddress().getHostAddress();
        }
        this.passiveHost = pasvHost;
        this.passivePort = pasvPort;
    }