Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I can't reproduce this myself, but I have an idea of what's happening -- I'm just not sure <em>how</em> it's happening. Hopefully someone can chime in. Note that <code>file</code> isn't passed through to handleDownload, and <code>file</code> is also the name of a builtin type. If <code>file</code> were left as the builtin, then you'd get exactly this error:</p> <pre><code>&gt;&gt;&gt; file &lt;type 'file'&gt; &gt;&gt;&gt; file.write("3") Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: descriptor 'write' requires a 'file' object but received a 'str' </code></pre> <p>So I think some of the problem is a confusion between <code>file</code>, the built-in, and <code>file</code>, the opened file itself. (Probably using a name other than <code>"file"</code> is a good idea here.) Anyway, if you simply use</p> <pre><code>ftp.retrbinary('RETR ' + filename, file.write) </code></pre> <p>and ignore the <code>handleDownload</code> function entirely, it should work. Alternatively, if you wanted to keep the dots printing every block, you could be a little fancier, and write something like</p> <pre><code>def handleDownloadMaker(openfile): def handleDownload(block): openfile.write(block) print ".", return handleDownload </code></pre> <p>which is a function which <em>returns</em> a function that points at the right file. After that,</p> <pre><code>ftp.retrbinary('RETR' + filename, handleDownloadMaker(file)) </code></pre> <p>should work too.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload