def download_db(self) -> bool: """try to download the data set""" logger.debug('downloading WOA9 atlas') # FIXME: this was too dangerous if the user select the wrong folder # try: # # remove all the content # for root, dirs, files in os.walk(self.data_folder, topdown=False): # for name in files: # os.remove(os.path.join(root, name)) # for name in dirs: # os.rmdir(os.path.join(root, name)) # except Exception as e: # logger.error('during cleaning target folder: %s' % e) # return False try: ftp = Ftp("ftp.ccom.unh.edu", show_progress=True, debug_mode=False, progress=self.prj.progress) data_zip_src = "fromccom/hydroffice/woa09.red.zip" data_zip_dst = os.path.abspath(os.path.join(self.data_folder, os.pardir, "woa09.red.zip")) ftp.get_file(data_zip_src, data_zip_dst, unzip_it=True) ftp.disconnect() return self.is_present() except Exception as e: logger.error('during WOA09 download and unzip: %s' % e) return False
def test_get_file(self): data_folder = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) testing = Testing(root_folder=data_folder) ftp = Ftp(host="ftp.ccom.unh.edu", password="******", show_progress=True, debug_mode=True) ftp.get_file( file_src="fromccom/hydroffice/Caris_Support_Files_5_5.zip", file_dst=os.path.join(testing.output_data_folder(), "test.zip")) ftp.disconnect()
def download_from_unh(self): """try to download the data set""" logger.debug('downloading NOAA Caris Support Files from UNH FTP') if not self.delete_local_noaa_support_files(): return False try: ftp = Ftp("ftp.ccom.unh.edu", show_progress=True, debug_mode=False, progress=self.progress) data_zip_src = "fromccom/hydroffice/Caris_Support_Files_%s.zip" % self.v_version() ftp.get_file(data_zip_src, self.local_zip_path, unzip_it=True) return self.local_noaa_support_folder_present() except Exception as e: logger.error('during WOA09 download and unzip: %s' % e) return False
def download_from_noaa(self): """try to download the data set""" logger.debug('downloading NOAA Caris Support Files from NOAA FTP') if not self.delete_local_noaa_support_files(): return False try: # ftp.ocsftp.ncd.noaa.gov ftp = Ftp("205.156.4.84", show_progress=True, debug_mode=False, progress=self.progress) data_zip_src = "HSD/Customization_Files/CARIS/Caris_Support_Files_%s.zip" % self.v_version() ftp.get_file(data_zip_src, self.local_zip_path, unzip_it=True) return self.local_noaa_support_folder_present() except Exception as e: traceback.print_exc() logger.error('during download and unzip: %s' % e) return False
# create an empty `download` folder download_folder = os.path.join(os.path.abspath(os.path.dirname(__file__)), "download") if not os.path.exists(download_folder): os.makedirs(download_folder) elif clear_download_folder: shutil.rmtree(download_folder) os.makedirs(download_folder) raw_km_folder = os.path.join(download_folder, "raw_km") if not os.path.exists(raw_km_folder): os.makedirs(raw_km_folder) elif clear_download_folder: shutil.rmtree(raw_km_folder) os.makedirs(raw_km_folder) # actually downloading the file with wget for fid in data_files: data_src = os.path.join("fromccom/hydroffice/openbst/testdata/raw_km", fid) data_dst = os.path.abspath(os.path.join(raw_km_folder, fid)) print("> downloading %s to %s" % (data_src, data_dst)) try: ftp = Ftp("ftp.ccom.unh.edu", show_progress=True, debug_mode=False) ftp.get_file(data_src, data_dst, unzip_it=False) ftp.disconnect() except Exception as e: logger.error('while downloading %s: %s' % (fid, e))