Download specific file from FTP using python
<p>quick and simple:</p>

<p>I have the following function, works well if i specify the file name.</p>

<pre><code>import os
import ftplib

def ftpcon(self, host, port, login, pwd, path):

    ftp = ftplib.FTP()
    ftp.connect(host, port, 20)
    try:

        ftp.login(login, pwd)
        ftp.cwd(path)

        for files in ftp.nlst():

            if files.endswith('.doc') or files.endswith('.DOC'):

                ftp.retrbinary('RETR ' + files, open(file, 'wb').write)
                print files
</code></pre>

<p>But when i use the for loop with ftp.nlst() to try to match an specific type of file, i receive the error:</p>

<blockquote>
  <p>coercing to Unicode: need string or buffer, type found</p>
</blockquote>

<p>Since im not sure if this is the best way to do it, what could the "correct" way to download a file ? </p>
