# -*- coding: utf-8 -*-
"""
Created on Wed Nov 01 13:00:26 2017
@author: Baikal
"""
from ftplib import FTP
import os
import urllib2
def Download_CIS( Root_dir, Sub_dir, Position, Year, CIS_Root_DIR, CIS_SUB_DIR ):
CIS_DIR = os.path.join( CIS_Root_DIR, Year, CIS_SUB_DIR )
os.chdir( CIS_DIR )
Web_Sub_dir = Sub_dir + '/' + Position + '/' + Year
ftp = FTP( Root_dir )
#Log in anonymous
ftp.login()
# Change the directory.
ftp.cwd( Web_Sub_dir )
lists = ftp.nlst()
for list in lists:
if list.endswith( '.tar' ):
Website_file_dir = 'ftp://' + Root_dir + '/' + Web_Sub_dir + '/' + list
CIS_data = urllib2.urlopen( Website_file_dir ).read( )
CIS_File = os.path.join( CIS_DIR, list )
with open( CIS_File, 'wb' ) as Data:
Data.write( CIS_data )
print list + 'has written down'
##
Root_dir = 'sidads.colorado.edu'
Sub_dir = 'pub/DATASETS/NOAA/G02171'
Position = 'Western_Arctic'
Year = '2018'
CIS_Root_DIR = r'G:\CIS_Sea_Ice_Chart_3573'
if Position == 'Western_Arctic':
CIS_SUB_DIR = 'WA'
else:
CIS_SUB_DIR = 'EA'
Download_CIS( Root_dir, Sub_dir, Position, Year, CIS_Root_DIR, CIS_SUB_DIR )
Reference:
https://stackoverflow.com/questions/13534807/python-ftplib-connection-error-gaierror
"""
Created on Wed Nov 01 13:00:26 2017
@author: Baikal
"""
from ftplib import FTP
import os
import urllib2
def Download_CIS( Root_dir, Sub_dir, Position, Year, CIS_Root_DIR, CIS_SUB_DIR ):
CIS_DIR = os.path.join( CIS_Root_DIR, Year, CIS_SUB_DIR )
os.chdir( CIS_DIR )
Web_Sub_dir = Sub_dir + '/' + Position + '/' + Year
ftp = FTP( Root_dir )
#Log in anonymous
ftp.login()
# Change the directory.
ftp.cwd( Web_Sub_dir )
lists = ftp.nlst()
for list in lists:
if list.endswith( '.tar' ):
Website_file_dir = 'ftp://' + Root_dir + '/' + Web_Sub_dir + '/' + list
CIS_data = urllib2.urlopen( Website_file_dir ).read( )
CIS_File = os.path.join( CIS_DIR, list )
with open( CIS_File, 'wb' ) as Data:
Data.write( CIS_data )
print list + 'has written down'
##
Root_dir = 'sidads.colorado.edu'
Sub_dir = 'pub/DATASETS/NOAA/G02171'
Position = 'Western_Arctic'
Year = '2018'
CIS_Root_DIR = r'G:\CIS_Sea_Ice_Chart_3573'
if Position == 'Western_Arctic':
CIS_SUB_DIR = 'WA'
else:
CIS_SUB_DIR = 'EA'
Download_CIS( Root_dir, Sub_dir, Position, Year, CIS_Root_DIR, CIS_SUB_DIR )
Reference:
https://stackoverflow.com/questions/13534807/python-ftplib-connection-error-gaierror
没有评论:
发表评论