How to download a specific file type from all subdirectories of an FTP server?
Question: I am trying to download all `.laz` files from the FTP host `gis.arkansas.gov`
(more details [here](http://gis.arkansas.gov/?page_id=7813)). Looking at the
[`ftplib`](https://docs.python.org/2.7/library/ftplib.html) documentation, I
see that I can list all of the directories in the FTP server:

    
    
    from ftplib import FTP
    ftp = FTP('gis.arkansas.gov')
    ftp.login()
    ftp.cwd('Elevation')
    ftp.retrlines('LIST')
    

* * *

Which yields the following:

    
    
    >>> ftp.retrlines('LIST')
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 AGFC_RAW
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 AR State Parks
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 Bayou Meto Lidar Phase I
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 Bayou_Meto_Watershed
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 Beaver_Lake
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 Beaver_Tailwater
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 Black_River
    drwxr-xr-x 1 ftp ftp              0 May 30 09:24 Blue_Mountain
    # ... And so on ...
    

How can I download all of the files with a .laz extension from each of these
directories (some directories do not contain .laz files)?


Answer: There's no magic.

You have to:

  * recurse into the subdirectories,
  * list their contents one by one,
  * filter all `.laz` files,
  * call `retrbinary` for each.

