Python equivalent of this Curl command
<p>I am trying to download a file using python, imitating the same behavior as this curl command:</p>

<pre><code>curl  ftp://username:password@example.com \
    --retry 999 \
    --retry-max-time 0
    -o 'target.txt' -C -
</code></pre>

<p>How would this look in python ?</p>

<p>Things I have looked into:</p>

<ul>
<li><p>Requests : no ftp support</p></li>
<li><p>Python-wget: no download resume support</p></li>
<li><p>requests-ftp : no download resume support</p></li>
<li><p>fileDownloader : broken(?)</p></li>
</ul>

<p>I am guessing one would need to build this from scratch and go low level with pycurl or urllib2 or something similar.</p>

<p>I am trying to create this script in python and I feel lost..  Should I just call curl from python subprocess ?</p>

<p>Any point to the write direction would be much appreciated</p>

<p>you can use python's inbuilt ftplib</p>

<p>Here is the code:</p>

<pre><code>from ftplib import FTP

ftp = FTP('example.com', 'username', 'password') #logs in

ftp.retrlines() # to see the list of files and directories ftp.cwd('to change to any directory')

ftp.retrbinary('RETR filename', open('Desktop\filename', 'wb').write) # start downloading

ftp.close() # close the connection
</code></pre>

<p>Auto resume is supported. I even tried turning off my wifi and checked if the download is resuming.</p>

<p>You can refer to /Python27/Lib/ftplib.py for default GLOBAL_TIME_OUT settings.</p>

python curl