diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index c76d3028..c4396d38 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -210,10 +210,14 @@ class ResMrpWorkOrder(models.Model): local_dir_path = '/ftp/before' os.makedirs(local_dir_path, exist_ok=True) - local_filename = 'WH_MO_00099.xls' + local_filename = self.save_name + '.xls' local_file_path = os.path.join(local_dir_path, local_filename) logging.info('local_file_path:%s' % local_file_path) - remote_path = '/home/ftp/ftp_root/ThreeTest/XT/Before/WH_MO_00099.xls' + remote_path = '/home/ftp/ftp_root/ThreeTest/XT/Before/' + local_filename + logging.info('remote_path:%s' % remote_path) + + if not ftp.file_exists(remote_path): + raise UserError(f"文件不存在: {remote_path}") with open(local_file_path, 'wb') as local_file: ftp.ftp.retrbinary('RETR ' + remote_path, local_file.write) diff --git a/sf_mrs_connect/models/ftp_operate.py b/sf_mrs_connect/models/ftp_operate.py index c8d0abb6..724f56b4 100644 --- a/sf_mrs_connect/models/ftp_operate.py +++ b/sf_mrs_connect/models/ftp_operate.py @@ -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):