diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPClient.java index 81239237c..da9016baa 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -828,10 +828,20 @@ protected void _parseExtendedPassiveModeReply(String reply) throws MalformedServ throw new MalformedServerReplyException("Could not parse extended passive host information.\nServer Reply: " + reply); } // in EPSV mode, the passive host address is implicit - passiveHost = getRemoteAddress().getHostAddress(); + passiveHost = resolveExtendedPassiveModeHost(); passivePort = port; } + /** + * Resolve the host for extended passive mode. + * + * @since 3.14.0 + * @return the passive host + */ + protected String resolveExtendedPassiveModeHost() { + return getRemoteAddress().getHostAddress(); + } + /** * Parses a reply. * diff --git a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java index bd49af4e8..a582ed3c2 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java @@ -1119,5 +1119,14 @@ protected void sslNegotiation() throws IOException { throw new SSLHandshakeException("Hostname doesn't match certificate"); } } + + @Override + protected String resolveExtendedPassiveModeHost() { + if (_socket_ instanceof SSLSocket) { + return ((SSLSocket) _socket_).getSession().getPeerHost(); + } else { + return super.resolveExtendedPassiveModeHost(); + } + } }