From b0506437148a3ba3ec2863dfdd4484f589d3fd1f Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 16 Apr 2024 19:42:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=87=E4=BB=B6=E5=A4=8D=E5=88=B6?= =?UTF-8?q?=E6=97=B6=E5=88=A4=E6=96=AD=E7=9B=AE=E5=BD=95=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/utils/ssh/ssh.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/framework/utils/ssh/ssh.go b/src/framework/utils/ssh/ssh.go index 54ddb94a..7790f17d 100644 --- a/src/framework/utils/ssh/ssh.go +++ b/src/framework/utils/ssh/ssh.go @@ -422,6 +422,10 @@ func (s *SSHClientSFTP) CopyFileRemoteToLocal(remotePath, localPath string) erro } defer remoteFile.Close() + if err := os.MkdirAll(filepath.Dir(localPath), 0750); err != nil { + return err + } + // 如果目标文件已经存在,先将目标文件重命名 if info, err := os.Stat(localPath); err == nil && !info.IsDir() { ext := filepath.Ext(localPath) @@ -460,6 +464,12 @@ func (s *SSHClientSFTP) CopyFileLocalToRemote(localPath, remotePath string) erro } defer localFile.Close() + // 创建远程目录 + if err := s.Client.MkdirAll(filepath.Dir(remotePath)); err != nil { + logger.Errorf("CopyFileLocalToRemote failed to creating remote directory %s: => %s", remotePath, err.Error()) + return err + } + // 创建远程文件 remoteFile, err := s.Client.Create(remotePath) if err != nil {