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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
_______________________________________________
Yum mailing list
Yum@xxxxxxxxxxxxxxxxxxxx
https://lists.dulug.duke.edu/mailman/listinfo/yum

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux