def _download_ftp(self, service_key, app_version, namespace, is_md5=False): """ 云帮ftp下载文件 """ utils = FTPUtils( host=self.ALL_REGION_FTP_HOST, username=self.ALL_REGION_FTP_USERNAME, password=self.ALL_REGION_FTP_PASSWORD, namespace=self.ALL_REGION_FTP_NAMESPACE, port=self.ALL_REGION_FTP_PORT) logger.info("mq_work.app_slug", "*******[download]download file from ftp") # 检查service_key对应的文件是否存在,不存在生成 remote_file = self.ALL_REGION_FTP_PATH.format( serviceKey=service_key, appVersion=app_version) if is_md5: remote_file += ".md5" if not namespace: logger.info("mq_work.app_slug", "*******[download]namespace is null") logger.error("mq_work.app_slug", "*******[download]namespace is null") else: logger.info("mq_work.app_slug", "*******[download]namespace is {}".format(namespace)) remote_file = "../" + namespace + "/" + remote_file logger.info("mq_work.app_slug", "*******[download]remote file is {}".format(remote_file)) curr_region_slug = self.CURR_REGION_PATH.format( serviceKey=service_key, appVersion=app_version) if is_md5: curr_region_slug += ".md5" logger.info( "mq_work.app_slug", "*******[download]curr_region_slug is {}".format(curr_region_slug)) return utils.download(remote_file, curr_region_slug)
def _upload_ftp(self, service_key, app_version, md5file): """ 上传文件到ftp """ utils = FTPUtils( host=self.ALL_REGION_FTP_HOST, username=self.ALL_REGION_FTP_USERNAME, password=self.ALL_REGION_FTP_PASSWORD, namespace=self.ALL_REGION_FTP_NAMESPACE, port=self.ALL_REGION_FTP_PORT) # 检查service_key对应的文件是否存在,不存在生成 service_dir = self.ALL_REGION_FTP_NAMESPACE + service_key logger.debug("mq_work.app_slug", 'slug task is {}'.format(self.task)) logger.debug("mq_work.app_slug", '*******upload dir is {}'.format(service_dir)) utils.check_dir(service_dir) # 上传文件 curr_region_slug = self.CURR_REGION_PATH.format( serviceKey=service_key, appVersion=app_version) logger.debug("mq_work.app_slug", '*******upload file path is {}'.format(curr_region_slug)) utils.upload(service_dir, curr_region_slug) # 上传md5文件 if md5file: utils.upload(service_dir, md5file) return True