]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
SF patch #497420 (Eduardo Pérez): ftplib: ftp anonymous password
authorMartin v. Löwis <martin@v.loewis.de>
Tue, 20 May 2003 06:16:55 +0000 (06:16 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Tue, 20 May 2003 06:16:55 +0000 (06:16 +0000)
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

index 01895fd66862f089a15621577fae662d87d7e2eb..f7535fc6ad3bd079938b9df27ee12739172f6b9f 100644 (file)
@@ -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)