下发完成后,关闭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)
_logger.info("======%s下发成功======" % a.display_name)
up_time = str(datetime.now())
ftp.close_ftp()
up_time = str(datetime.now())
self.env['delivery.record'].create({
'workorder_id': self.workorder_id.id,
'delivery_type': '单个下发',
@@ -296,6 +297,7 @@ class WorkCenterBarcode(models.Model):
ftp.upload_file(remotepath=file_path_remote, localpath=file_path_local)
_logger.info("======%s下发成功======" % a.display_name)
item.button_state = True
ftp.close_ftp()
# 增加一键下发记录
up_time = str(datetime.now())
sequence_str = ','.join(sequence_collect)

View File

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