优化ftp路径

This commit is contained in:
jinling.yang
2024-04-18 19:09:48 +08:00
parent 59670fb3d7
commit 053fa3feb3
2 changed files with 24 additions and 5 deletions

View File

@@ -37,8 +37,22 @@ class FtpController():
os.makedirs(serverdir)
try:
logging.info("进入FTP目录 ")
self.ftp.cwd(target_dir) # 切换工作路径
logging.info('FTP目录:%s' % target_dir)
logging.info('目录:%s' % target_dir)
target_dir1 = target_dir.split('/')
logging.info('目录1:%s' % target_dir1[1])
self.ftp.cwd(target_dir1[1])
logging.info('目录2:%s' % target_dir1[2])
self.ftp.cwd(target_dir1[2])
logging.info('目录3:%s' % target_dir1[3])
self.ftp.cwd(target_dir1[3])
logging.info('目录4:%s' % target_dir1[4])
self.ftp.cwd(target_dir1[4])
logging.info('目录5:%s' % target_dir1[5])
self.ftp.cwd(target_dir1[5])
logging.info('目录6:%s' % target_dir1[6])
self.ftp.cwd(target_dir1[6])
logging.info('目录7:%s' % target_dir1[7])
self.ftp.cwd(target_dir1[7])
remotenames = self.ftp.nlst()
logging.info('FTP目录文件:%s' % remotenames)
for file in remotenames:
@@ -48,6 +62,9 @@ class FtpController():
return 1
except Exception:
return 0
finally:
self.ftp.quit()
logging.info("ftp已关闭")
# 下载目录下的检测文件
def download_reportfile_tree(self, target_dir, serverdir, reportpath):
@@ -61,6 +78,8 @@ class FtpController():
self.ftp.cwd(target_dir1[1]) # 切换工作路径
logging.info('目录2:%s' % target_dir1[2])
self.ftp.cwd(target_dir1[2]) # 切换工作路径
logging.info('目录2:%s' % target_dir1[3])
self.ftp.cwd(target_dir1[3]) # 切换工作路径
remotenames = self.ftp.nlst()
logging.info('FTP目录检测报告文件:%s' % remotenames)
for filename in remotenames: