Created
December 22, 2011 02:16
-
-
Save zx1986/1508591 to your computer and use it in GitHub Desktop.
Get files through FTP from discover-earth
This file contains 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
#!/usr/bin/python | |
# -*-coding:utf-8-*- | |
from ftplib import FTP | |
import logging | |
import sys | |
import os | |
ftp_host="ftp.discover-earth.org" | |
ftp_dir="sst/daily/tmi_amsre/" | |
storage_dir="/存放檔案的資料夾的絕對路徑/" | |
log_file="/放 log 檔的絕對路徑/log 檔名" | |
logging.basicConfig(filename=log_file, level=logging.DEBUG,format='%(asctime)s %(message)s') | |
try: | |
ftp = FTP(ftp_host) | |
ftp.login() | |
ftp.cwd(ftp_dir) | |
files = ftp.nlst() | |
locate_files = os.listdir(storage_dir) | |
wanted_files = list(set(files)-set(locate_files)) | |
for f in wanted_files: | |
print "downloading " + f + " ..." | |
ftp.retrbinary('RETR '+f, open(storage_dir + "/" + f, "wb").write) | |
except : | |
typ,message,trackback = sys.exc_info() | |
print message | |
logging.error(message) | |
finally: | |
ftp.quit() | |
logging.info('FTP disconnect.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment