#!/usr/bin/env python

import urlimport
import sys

sys.path.append("http://mcdc.missouri.edu/pub/libs/python")

import ftputil

if len(sys.argv) != 3:
	print "%s <userid> <password>" % sys.argv[0]
        sys.exit()


host=ftputil.FTPHost('ftp.census.gov', sys.argv[1], sys.argv[2])

host.chdir('/acs2007_1yr/summaryfile')

for __root, __dirs, __files in host.walk(host.curdir):
    for __file in __files:
	if __file.startswith("all_") and __file.endswith(".zip"):
        	__remote_file=host.path.join(__root, __file)
        	try:
            		print "downloading %s" % __remote_file
            		host.download(__remote_file, r"./downloads/%s" % __file, 'b')
        	except:
            		print "Error downloading %s" % __remote_file
        
print "done downloading"

