Browse Source

修改flag 参数默认

master
xyiege 4 months ago
parent
commit
25ba678e1a
  1. 52
      scagent/core/FileRpc.go

52
scagent/core/FileRpc.go

@ -3,7 +3,6 @@ package core
import (
"fmt"
"net/rpc"
"os"
"path"
"path/filepath"
"scagent/config"
@ -90,6 +89,19 @@ func clientUploadFile(remote string, filePath string, uploadPath string) {
// 启用日志
logger := util.NewProductionLogger()
defer logger.Sync()
// 调用外部组件scalib 程序执行
// ./scalib -h 192.168.66.92:9098 -f /www/gfs/sync_zips/BIU_20251009_153640.zip /www/afs/logs/
// 执行命令
cmd := fmt.Sprintf("scalib -ip %s -port %s -file %s -upload %s", dstip, dport, filePath, uploadPath)
fmt.Printf("cmd: %s\n", cmd)
// 执行命令
err := util.ExecCommand(cmd)
if err != nil {
logger.Error("ExecCommand failed", zap.Error(err))
fmt.Printf("ExecCommand failed: %v\n", err)
return
}
// 将服务器的信息拆分为ip和端口
harr := strings.Split(remote, ":")
dstip := harr[0]
@ -111,41 +123,3 @@ func clientUploadFile(remote string, filePath string, uploadPath string) {
fmt.Printf("TransferFile success\n")
}
// 传输文件
func transferFile(c *UpFileClient, filePath string, uploadPath string) error {
// 发送文件信息
fmt.Printf("TransferFile filePath: %s, uploadPath: %s\n", filePath, uploadPath)
// 获取文件信息
fileInfo, err := os.Stat(filePath)
if err != nil {
// panic(err)
fmt.Printf("获取文件信息失败: %v\n", err)
return err
}
// 提取文件名
// 远程的文件名
fileName := filepath.Base(uploadPath)
fmt.Printf("fileName: %s\n", fileName)
// 远程服务器的路径
dirpath := filepath.Dir(uploadPath)
fmt.Printf("remote dirpath: %s\n", dirpath)
fmt.Printf("file size: %d\n", fileInfo.Size())
// 异步
go func() {
// 发送文件信息
var reply string
c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{
FileName: uploadPath,
FileSize: fileInfo.Size(),
}, &reply)
// 输出执行的结果
fmt.Printf("SendFileInfo result: %v\n", reply)
}()
return nil
}

Loading…
Cancel
Save