[Yum] [UG] ftpwrapper should fall back to PORT mode when retrieve file failed

余志昌 yuzhichang at gmail.com
Tue Mar 6 05:53:24 UTC 2007


Hi all,
  During using yum, I ofen found it cann't download
repodata/repomd.xml from a ftp repo, but I can use NcFTP (a command
line ftp client) download it. It's because that NcFTP fall back to
PORT if  PASV mode failed. (I'm inside a firewall which allow me
connect to only some famous outside port. So I cann't use the FTP PASV
mode to download anything!)
  Follow is a piece output of NcFTP:
ncftp / > get pub/freshrpms/ayo/fedora/linux/5/i386/freshrpms/repodata/repomd.xml
connect failed: Connection refused.
Falling back to PORT instead of PASV mode.
repomd.xml:                                        972.00 B    0.77 B/s

  I think this is a bug of urlgrabber/byterange.py(I use urlgrabber
version 3.1.0, old version has this bug too). I changed a piece of
code in methon ftpwrapper.retrfile()from:
        if file and not isdir:
            # Use nlst to see if the file exists at all
            try:
                self.ftp.nlst(file)
            except ftplib.error_perm, reason:
                raise IOError, ('ftp error', reason), sys.exc_info()[2]

to:
        if file and not isdir:
            # Use nlst to see if the file exists at all
            try:
                self.ftp.nlst(file)
            except ftplib.error_perm:
            # Falling back to PORT instead of PASV mode
                self.ftp.set_pasv(False)
                self.ftp.nlst(file)

  Then I reinstall urlgrabber, and run my testsuit:

#!/usr/bin/env python
import urllib2
import urlgrabber
from urlgrabber.byterange import *
range_handler = FTPRangeHandler()
opener = urllib2.build_opener(range_handler)
# install it
urllib2.install_opener(opener)
# create Request and set Range header
req = urllib2.Request('ftp://ftp.freshrpms.net/pub/freshrpms/ayo/fedora/linux/5/i386/freshrpms/repodata/repomd.xml')
f = urllib2.urlopen(req)

  Everything is good now. I catch all ftp packets, which show me that
my code falls back to PORT when PASV mode failed.



More information about the Yum mailing list