Skip to content

gh-127478: Enhancement to support FTP connection with NAT scenario #127477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
6 changes: 5 additions & 1 deletion Lib/ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ def makeport(self):
def makepasv(self):
"""Internal: Does the PASV or EPSV handshake -> (address, port)"""
if self.af == socket.AF_INET:
untrusted_host, port = parse227(self.sendcmd('PASV'))
pasv_response = self.sendcmd('PASV')
try:
untrusted_host, port = parse227(pasv_response)
except error_reply:
untrusted_host, port = parse229(pasv_response, self.sock.getpeername())
if self.trust_server_pasv_ipv4_address:
host = untrusted_host
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enhancement to support FTP connection with NAT scenario.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to come up with a better NEWS entry here for tomorrow but otherwise thank you.

Loading