下发完成后,关闭ftp连接

This commit is contained in:
mgw
2023-02-27 09:52:17 +08:00
parent 8247acb79a
commit 57d403d754
3 changed files with 12 additions and 1 deletions

View File

@@ -77,8 +77,9 @@ class FtpButton(models.Model):
# 存在本地的文件下发到机床 # 存在本地的文件下发到机床
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local) ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
_logger.info("======%s下发成功======" % a.display_name) _logger.info("======%s下发成功======" % a.display_name)
up_time = str(datetime.now()) ftp.close_ftp()
up_time = str(datetime.now())
self.env['delivery.record'].create({ self.env['delivery.record'].create({
'workorder_id': self.workorder_id.id, 'workorder_id': self.workorder_id.id,
'delivery_type': '单个下发', 'delivery_type': '单个下发',
@@ -296,6 +297,7 @@ class WorkCenterBarcode(models.Model):
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local) ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
_logger.info("======%s下发成功======" % a.display_name) _logger.info("======%s下发成功======" % a.display_name)
item.button_state = True item.button_state = True
ftp.close_ftp()
# 增加一键下发记录 # 增加一键下发记录
up_time = str(datetime.now()) up_time = str(datetime.now())
sequence_str = ','.join(sequence_collect) sequence_str = ','.join(sequence_collect)

View File

@@ -78,6 +78,13 @@ class FtpController:
with open(localpath, mode='rb') as file: with open(localpath, mode='rb') as file:
self.ftp.storbinary('STOR ' + remotepath, file, bufsize) self.ftp.storbinary('STOR ' + remotepath, file, bufsize)
# 关闭连接
def close_ftp(self):
"""
下发完成后关闭ftp连接减少资源损耗
"""
self.ftp.close()
def delAllfile(self, ftppath): def delAllfile(self, ftppath):
""" """

View File

@@ -67,6 +67,8 @@ class UpSelectWizard(models.TransientModel):
_logger.info("======%s下发成功======" % a.display_name) _logger.info("======%s下发成功======" % a.display_name)
# 下发成功标识 # 下发成功标识
item.button_state = True item.button_state = True
ftp.close_ftp()
up_time = str(datetime.now()) up_time = str(datetime.now())
sequence_str = ','.join(sequence_collect) sequence_str = ','.join(sequence_collect)
self.workorder_id.delivery_records.create({ self.workorder_id.delivery_records.create({