From 4f924a943f60e05a28eca7701f0c7f082505fa2a Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Mon, 19 Aug 2024 19:03:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BD=91=E5=85=83=E7=AB=AF=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9B=AE=E5=BD=95/tmp/omc=20=E4=B8=8A=E4=BC=A0push=20?= =?UTF-8?q?=E4=B8=8B=E8=BD=BDpull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/network_element/controller/action.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/network_element/controller/action.go b/src/modules/network_element/controller/action.go index 4d597356..1e34c5be 100644 --- a/src/modules/network_element/controller/action.go +++ b/src/modules/network_element/controller/action.go @@ -9,6 +9,7 @@ import ( "be.ems/src/framework/i18n" "be.ems/src/framework/utils/ctx" "be.ems/src/framework/utils/file" + "be.ems/src/framework/utils/generate" "be.ems/src/framework/utils/ssh" "be.ems/src/framework/vo/result" neService "be.ems/src/modules/network_element/service" @@ -68,7 +69,9 @@ func (s *NeActionController) PushFile(c *gin.Context) { // 本地文件 localFilePath := file.ParseUploadFilePath(body.UploadPath) - neFilePath := fmt.Sprintf("/tmp/%s", filepath.Base(localFilePath)) + // 网元端临时目录 + sshClient.RunCMD("mkdir -p /tmp/omc && sudo chmod 777 -R /tmp/omc") + neFilePath := filepath.Join("/tmp/omc/push", filepath.Base(localFilePath)) // 复制到远程 if err = sftpClient.CopyFileLocalToRemote(localFilePath, neFilePath); err != nil { c.JSON(200, result.ErrMsg(fmt.Sprintf("%s : please check if scp remote copy is allowed", neInfo.NeType))) @@ -116,8 +119,9 @@ func (s *NeActionController) PullFile(c *gin.Context) { } defer sftpClient.Close() - nePath := fmt.Sprintf("%s/%s", querys.Path, querys.FileName) - localFilePath := fmt.Sprintf("/tmp/omc/pullFile%s", nePath) + nePath := filepath.Join(querys.Path, querys.FileName) + fileName := generate.Code(6) + "_" + querys.FileName + localFilePath := filepath.Join("/tmp/omc/pull", fileName) if runtime.GOOS == "windows" { localFilePath = fmt.Sprintf("C:%s", localFilePath) } @@ -126,7 +130,7 @@ func (s *NeActionController) PullFile(c *gin.Context) { c.JSON(200, result.ErrMsg(err.Error())) return } - c.FileAttachment(localFilePath, querys.FileName) + c.FileAttachment(localFilePath, fileName) } // 网元端文件列表