优化代码健壮性,解决部分硬编码问题
This commit is contained in:
@@ -21,6 +21,16 @@ class FtpController():
|
||||
except Exception:
|
||||
logging.info("ftp连接失败")
|
||||
|
||||
def file_exists(self, path):
|
||||
# 检查文件是否存在于FTP服务器上
|
||||
try:
|
||||
self.ftp.cwd(os.path.dirname(path))
|
||||
files = self.ftp.nlst()
|
||||
return os.path.basename(path) in files
|
||||
except Exception as e:
|
||||
logging.error(f"Error checking file: {e}")
|
||||
return False
|
||||
|
||||
# 下载目录下的文件
|
||||
def download_file_tree(self, target_dir, serverdir):
|
||||
if not os.path.exists(serverdir):
|
||||
|
||||
Reference in New Issue
Block a user