Skip to content

Instantly share code, notes, and snippets.

@zx1986
Created December 22, 2011 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zx1986/1508591 to your computer and use it in GitHub Desktop.
Save zx1986/1508591 to your computer and use it in GitHub Desktop.
Get files through FTP from discover-earth
#!/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