From e79ea30e52e20f8132cc163ac77b2c4737149bc1 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 24 Jul 2024 17:20:27 +0800 Subject: [PATCH] =?UTF-8?q?style:=20ssh=E6=96=87=E4=BB=B6=E6=93=8D?= =?UTF-8?q?=E4=BD=9Clog=E6=97=A5=E5=BF=97s=E8=BE=93=E5=87=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/framework/utils/ssh/sftp.go | 10 ++++++++-- src/framework/utils/ssh/ssh.go | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/framework/utils/ssh/sftp.go b/src/framework/utils/ssh/sftp.go index 2fd826fc..f5c103f7 100644 --- a/src/framework/utils/ssh/sftp.go +++ b/src/framework/utils/ssh/sftp.go @@ -80,7 +80,7 @@ func (s *SSHClientSFTP) CopyDirLocalToRemote(localDir, remoteDir string) error { } else { // 如果是文件,则复制文件内容 if err := s.CopyFileLocalToRemote(localPath, remotePath); err != nil { - logger.Errorf("CopyFileLocalToRemote failed to opening local file %s: => %s", localPath, err.Error()) + logger.Errorf("CopyDirLocalToRemote failed to copying remote file %s: => %s", localPath, err.Error()) return err } } @@ -88,7 +88,7 @@ func (s *SSHClientSFTP) CopyDirLocalToRemote(localDir, remoteDir string) error { return nil }) if err != nil { - logger.Errorf("CopyDirLocalToRemote failed to walking local directory: => %s", err.Error()) + logger.Errorf("CopyDirLocalToRemote failed to walking remote directory: => %s", err.Error()) return err } return nil @@ -134,6 +134,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 { diff --git a/src/framework/utils/ssh/ssh.go b/src/framework/utils/ssh/ssh.go index 29a5fb70..d70991e7 100644 --- a/src/framework/utils/ssh/ssh.go +++ b/src/framework/utils/ssh/ssh.go @@ -100,6 +100,7 @@ func (c *ConnSSH) RunCMD(cmd string) (string, error) { defer session.Close() buf, err := session.CombinedOutput(cmd) if err != nil { + logger.Infof("RunCMD failed run command: => %s", cmd) logger.Errorf("RunCMD failed run command: => %s", err.Error()) } c.LastResult = string(buf)