class RFTP: def __init__(self): ftp_path = getattr(settings, 'FTP_PATH', 'ftp://*****:*****@192.168.60.70/soft/测试文件') parsed = urlparse(ftp_path) self.hostname = parsed.hostname self.username = parsed.username self.password = parsed.password self.path = parsed.path self.ftp = None def get_ftp(self): if self.ftp is None: self.ftp = FTPHost(self.hostname, self.username, self.password) self.ftp.chdir(self.path) else: try: self.ftp.chdir(self.path) except Exception as e: self.ftp = FTPHost(self.hostname, self.username, self.password) self.ftp.chdir(self.path) return self.ftp def remove_file(self, name): try: self.ftp.remove(name) except Exception as e: self.ftp.rmdir(name)
def remove(self, path): FTPHost.remove(self, path) self._invalidate_dir(path)