style: ssh文件操作log日志s输出信息

This commit is contained in:
TsMask
2024-07-24 17:20:27 +08:00
parent 7b39972f2c
commit e79ea30e52
2 changed files with 9 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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)