|
|
|
@ -97,6 +97,7 @@ func clientUploadFile(remote string, filePath string, uploadPath string) { |
|
|
|
if err != nil { |
|
|
|
logger.Error("NewUpFileClient failed", zap.Error(err)) |
|
|
|
} |
|
|
|
defer client.rpcClient.Close() |
|
|
|
// 调用 transferFile
|
|
|
|
err = client.TransferFile(filePath, uploadPath) |
|
|
|
if err != nil { |
|
|
|
@ -110,6 +111,7 @@ func clientUploadFile(remote string, filePath string, uploadPath string) { |
|
|
|
|
|
|
|
// 传输文件
|
|
|
|
func (c *UpFileClient) TransferFile(filePath string, uploadPath string) error { |
|
|
|
fmt.Printf("TransferFile filePath: %s, uploadPath: %s\n", filePath, uploadPath) |
|
|
|
// 发送文件信息
|
|
|
|
// 获取文件信息
|
|
|
|
fileInfo, err := os.Stat(filePath) |
|
|
|
@ -123,17 +125,23 @@ func (c *UpFileClient) TransferFile(filePath string, uploadPath string) error { |
|
|
|
// 远程的文件名
|
|
|
|
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()) |
|
|
|
|
|
|
|
// 发送文件信息
|
|
|
|
var reply bool |
|
|
|
err = c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{ |
|
|
|
FileName: filePath, |
|
|
|
FileSize: fileInfo.Size(), |
|
|
|
}, &reply) |
|
|
|
if err != nil { |
|
|
|
fmt.Printf("发送文件信息失败: %v\n", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
fmt.Printf("replay: %v\n", reply) |
|
|
|
var reply string |
|
|
|
// 异步
|
|
|
|
go func() { |
|
|
|
c.rpcClient.Call("UpFileService.SendFileInfo", FileInfo{ |
|
|
|
FileName: uploadPath, |
|
|
|
FileSize: fileInfo.Size(), |
|
|
|
}, &reply) |
|
|
|
// 输出执行的结果
|
|
|
|
fmt.Printf("SendFileInfo result: %s\n", reply) |
|
|
|
}() |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|