Last active
September 20, 2016 16:00
-
-
Save mhweber/5619e1c862bb11198a24cc1a0bfcb54c to your computer and use it in GitHub Desktop.
Example of ftp download for StreamCat data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Tue Sep 20 08:20:02 2016 | |
| @author: mweber | |
| """ | |
| import os | |
| from ftplib import FTP | |
| outdir = 'c:/users/mweber/temp/' | |
| ftp = FTP('newftp.epa.gov') | |
| ftp.login() | |
| ftp.cwd("/EPADataCommons/ORD/NHDPlusLandscapeAttributes/StreamCat/HydroRegions/") #just need to set this upper directory for each state | |
| filelist=ftp.nlst() | |
| for filename in filelist: | |
| if filename.count("STATSGO_Set2_Region07.csv"): | |
| download_file = filename | |
| print "Downloading ", download_file | |
| outfile=open(outdir + download_file,'wb') | |
| ftp.retrbinary('RETR ' + download_file, outfile.write, 1024) | |
| ftp.quit() | |
| outfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment