[Python-checkins] python/dist/src/Lib ftplib.py,1.60.10.3,1.60.10.4

loewis@users.sourceforge.net loewis@users.sourceforge.net
Mon, 19 May 2003 23:17:04 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv2601

Modified Files:
      Tag: release22-maint
	ftplib.py 
Log Message:
SF patch #497420 (Eduardo Pérez): ftplib: ftp anonymous password

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.


Index: ftplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/ftplib.py,v
retrieving revision 1.60.10.3
retrieving revision 1.60.10.4
diff -C2 -d -r1.60.10.3 -r1.60.10.4
*** ftplib.py	11 Mar 2002 10:20:36 -0000	1.60.10.3
--- ftplib.py	20 May 2003 06:16:55 -0000	1.60.10.4
***************
*** 7,11 ****
  >>> from ftplib import FTP
  >>> ftp = FTP('ftp.python.org') # connect to host, default port
! >>> ftp.login() # default, i.e.: user anonymous, passwd user@hostname
  '230 Guest login ok, access restrictions apply.'
  >>> ftp.retrlines('LIST') # list directory contents
--- 7,11 ----
  >>> from ftplib import FTP
  >>> ftp = FTP('ftp.python.org') # connect to host, default port
! >>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@
  '230 Guest login ok, access restrictions apply.'
  >>> ftp.retrlines('LIST') # list directory contents
***************
*** 352,368 ****
          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
          resp = self.sendcmd('USER ' + user)
          if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
--- 352,363 ----
          if not acct: acct = ''
          if user == 'anonymous' and passwd in ('', '-'):
! 	    # 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)