def upload(self, source_path, target_path=''): """Upload all files from given path to given bucket.""" source_path = join(self.path, source_path) if target_path.find('/') == 0: target_path = target_path[1:] if target_path.find('/') == -1 or target_path.rfind('/') == len(target_path)-1: target_path = target_path+'/' bucket = self.get_bucket() if bucket: files = [f for f in listdir(source_path) if isfile(join(source_path, f))] for _file in files: self.verbose_print("Uploading: "+str(target_path)+str(_file)) try: data = open(source_path+'/'+str(_file), 'rb') bucket.put_object(Key=str(target_path)+str(_file), Body=data) except Exception as e: print("Error during upload of "+str(target_path)+str(_file)+": "+str(e)) return False return True