Compare commits

...

4 Commits

  1. 7
      scagent/core/FileRpc.go
  2. 24
      scagent/core/UpFile.go
  3. 2
      scalib/build.bat
  4. 13
      scalib/main.go

7
scagent/core/FileRpc.go

@ -76,11 +76,11 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error {
taskId <- "upok"
}()
// 等待上传完成
rest := <-taskId
if strings.EqualFold(strings.ToLower(rest), "upok") {
logger.Info("上传文件", zap.String("filename", zpFileName), zap.String("path", remotePath))
// 解压缩文件,文件存在的文化
util.DecompressZip(remotePath)
logger.Info("解压缩文件", zap.String("filename", zpFileName), zap.String("path", remotePath))
// 上传完成后删除本地压缩包
// util.DeleteFile(ziprl)
}
@ -94,6 +94,9 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error {
// 客户端调用RPC传送文件的函数
// 传入zip的实际路径,远程的服务器带端口,远程文件存放路径
// remote 远程主机地址,带端口
// filePath 本地文件路径
// uploadPath 远程主机的存储路径
func clientUploadFile(remote string, filePath string, uploadPath string) {
fmt.Printf("remote: %s, filePath: %s, uploadPath: %s\n", remote, filePath, uploadPath)
// 启用日志

24
scagent/core/UpFile.go

@ -37,21 +37,16 @@ func (f *UpFileService) SendFileInfo(info FileInfo, reply *string) error {
// }
// 提取路径 /www/wwwroot/bidemo.com/BIU_20250918_183144.zip
// fmt.Printf("SendFileInfo fileName: %s\n", info.FileName)
dirPath := filepath.Dir(info.FileName)
logger.Info("SendFileInfo", zap.String("dirPath", dirPath))
// *reply = fmt.Sprintf("folder: %s is exists", dirPath)
// 检查文件夹是否存在
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
// 文件夹不存在,创建它
if err := os.MkdirAll(dirPath, 0755); err != nil {
logger.Error("SendFileInfo mkdir failed", zap.Error(err))
// *reply = fmt.Sprintf("mkdir folder: %s failed", dirPath)
// return err
}
}
// *reply = fmt.Sprintf("folder: %s is exists", dirPath)
// 返回true的字符串
*reply = "true"
return nil
@ -88,3 +83,22 @@ func (f *UpFileService) SendFileChunk(chunk FileChunk, reply *bool) error {
*reply = true
return nil
}
// 解压缩文件
// info.FileName 压缩包全路径
func (f *UpFileService) UnzipArchive(info FileInfo, reply *string) error {
// 日志
logger := util.NewProductionLogger()
defer logger.Sync()
// 解压缩文件
ret := make(chan string)
go func() {
util.DecompressZip(info.FileName)
ret <- "uzok"
}()
// 返回true的字符串
if retMsg := <-ret; retMsg == "uzok" {
*reply = retMsg
}
return nil
}

2
scalib/build.bat

@ -1,5 +1,5 @@
@echo off
color 87
color 8f
set GOOS=linux
set GOARCH=amd64
set CGO_ENABLED=0

13
scalib/main.go

@ -157,8 +157,19 @@ func transferFile(c *UpFileClient, curPath string, uploadPath string) error {
progress := float64(offset) / float64(fileInfo.Size()) * 100
fmt.Printf("\r发送进度: %.2f%%", progress)
}
fmt.Println("\n文件发送完成!")
// 文件解压缩
distFullName := filepath.Join(dirPath, fileName)
// 此时调用远程的完整路径,防止解压缩不成功
c.rpcClient.Call("UpFileService.UnzipArchive", FileInfo{
FileName: distFullName,
FileSize: fileInfo.Size(),
}, &reply)
// 输出执行的结果
if reply != "true" {
logger.Error("UnzipArchive failed", zap.String("reply", reply))
}
fmt.Printf("UnzipArchive success, reply: %s\n", reply)
// }()

Loading…
Cancel
Save