From 6c57bb830c4e8cae3726f12cbf16674efff85e7e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Tue, 20 May 2003 06:16:55 +0000 Subject: [PATCH] =?utf8?q?SF=20patch=20#497420=20(Eduardo=20P=C3=A9rez):?= =?utf8?q?=20ftplib:=20ftp=20anonymous=20password?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Instead of sending the real user and host, use "anonymous@" (i.e. no host name at all!) as the default anonymous FTP password. This avoids privacy violations. Backport of 1.62, 1.63. --- Lib/ftplib.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Lib/ftplib.py b/Lib/ftplib.py index 01895fd66862..f7535fc6ad3b 100644 --- a/Lib/ftplib.py +++ b/Lib/ftplib.py @@ -6,7 +6,7 @@ Example: >>> from ftplib import FTP >>> ftp = FTP('ftp.python.org') # connect to host, default port ->>> ftp.login() # default, i.e.: user anonymous, passwd user@hostname +>>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@ '230 Guest login ok, access restrictions apply.' >>> ftp.retrlines('LIST') # list directory contents total 9 @@ -351,19 +351,14 @@ class FTP: if not passwd: passwd = '' if not acct: acct = '' if user == 'anonymous' and passwd in ('', '-'): - # get fully qualified domain name of local host - thishost = socket.getfqdn() - try: - if os.environ.has_key('LOGNAME'): - realuser = os.environ['LOGNAME'] - elif os.environ.has_key('USER'): - realuser = os.environ['USER'] - else: - realuser = 'anonymous' - except AttributeError: - # Not all systems have os.environ.... - realuser = 'anonymous' - passwd = passwd + realuser + '@' + thishost + # If there is no anonymous ftp password specified + # then we'll just use anonymous@ + # We don't send any other thing because: + # - We want to remain anonymous + # - We want to stop SPAM + # - We don't want to let ftp sites to discriminate by the user, + # host or country. + passwd = passwd + 'anonymous@' resp = self.sendcmd('USER ' + user) if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd) if resp[0] == '3': resp = self.sendcmd('ACCT ' + acct) -- 2.47.3