How to download the same file twice? (urlretrieve issue)
<p>Python 2.7.</p>

<pre><code>from urllib import urlretrieve
urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file1")
urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file2")
</code></pre>

<p>The first download goes correctly but the second fails:</p>

<pre><code>Traceback (most recent call last):
  File "C:/Jacek/Python/untitled/test2.py", line 3, in &lt;module&gt;
    urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "file2")
  File "C:\Python27\lib\urllib.py", line 98, in urlretrieve
    return opener.retrieve(url, filename, reporthook, data)
  File "C:\Python27\lib\urllib.py", line 245, in retrieve
    fp = self.open(url, data)
  File "C:\Python27\lib\urllib.py", line 213, in open
return getattr(self, name)(url)
  File "C:\Python27\lib\urllib.py", line 558, in open_ftp
    (fp, retrlen) = self.ftpcache[key].retrfile(file, type)
  File "C:\Python27\lib\urllib.py", line 906, in retrfile
    conn, retrlen = self.ftp.ntransfercmd(cmd)
  File "C:\Python27\lib\ftplib.py", line 334, in ntransfercmd
    host, port = self.makepasv()
  File "C:\Python27\lib\ftplib.py", line 312, in makepasv
    host, port = parse227(self.sendcmd('PASV'))
  File "C:\Python27\lib\ftplib.py", line 830, in parse227
    raise error_reply, resp
IOError: [Errno ftp error] 200 TYPE is now 8-bit binary
</code></pre>

<p>On python 3 (with corresponding version of urlretrieve) this works as expected - both downloads succeeded.</p>

<p>Is it a way to resolve this on Python 2.7?</p>

<p>(Of course, you can say that downloading twice the same file doesn't make sense. I agree. I went into this problem while testing a module trying to download a file with different parameters (as it has nothing common with the problem, I simplified the example code) and I just was surprised with this strange behavior)</p>

<p>From the documentation for <a href="https://docs.python.org/2/library/urllib.html#urllib.urlretrieve" rel="nofollow">urlretrieve for Python2</a>:</p>

<p><code>If the URL points to a local file, or a valid cached copy of the object exists, the object is not copied</code></p>

<p>so the first impression is that the library will avoid the download the file twice.</p>

<p>Have you tried to write the file on different files?</p>

<pre><code>from urllib import urlretrieve
urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "/tmp/file1.gz")
urlretrieve("ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/mmCIF/27/127d.cif.gz", "/tmp/file2.gz")
</code></pre>

python python-2.7