Browse Source

调整rpc传输文件的函数

master
xyiege 6 months ago
parent
commit
3eeef1f2f1
  1. 10
      scagent/core/FileRpc.go

10
scagent/core/FileRpc.go

@ -103,7 +103,7 @@ func clientUploadFile(remote string, filePath string, uploadPath string) {
} }
defer client.rpcClient.Close() defer client.rpcClient.Close()
// 调用 transferFile // 调用 transferFile
err = client.TransferFile(filePath, uploadPath) err = transferFile(client, filePath, uploadPath)
if err != nil { if err != nil {
logger.Error("TransferFile failed", zap.Error(err)) logger.Error("TransferFile failed", zap.Error(err))
fmt.Printf("TransferFile failed: %v\n", err) fmt.Printf("TransferFile failed: %v\n", err)
@ -113,7 +113,7 @@ func clientUploadFile(remote string, filePath string, uploadPath string) {
} }
// 传输文件 // 传输文件
func (c *UpFileClient) TransferFile(filePath string, uploadPath string) error { func transferFile(client *UpFileClient, filePath string, uploadPath string) error {
// 发送文件信息 // 发送文件信息
fmt.Printf("TransferFile filePath: %s, uploadPath: %s\n", filePath, uploadPath) fmt.Printf("TransferFile filePath: %s, uploadPath: %s\n", filePath, uploadPath)
@ -135,10 +135,12 @@ func (c *UpFileClient) TransferFile(filePath string, uploadPath string) error {
fmt.Printf("remote dirpath: %s\n", dirpath) fmt.Printf("remote dirpath: %s\n", dirpath)
fmt.Printf("file size: %d\n", fileInfo.Size()) fmt.Printf("file size: %d\n", fileInfo.Size())
// 发送文件信息 fmt.Printf("rpcClient: %v\n", c.rpcClient)
var reply string
// 异步 // 异步
go func() { go func() {
// 发送文件信息
var reply string
c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{ c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{
FileName: uploadPath, FileName: uploadPath,
FileSize: fileInfo.Size(), FileSize: fileInfo.Size(),

Loading…
Cancel
Save