|
|
|
@ -36,7 +36,7 @@ type ZipBlock struct { |
|
|
|
Basepath string |
|
|
|
Curpath string // 当前路径
|
|
|
|
SelFile []string // 选中的文件
|
|
|
|
RemoteAdr string // 远程主机地址,带端口
|
|
|
|
RemoteAddr string // 远程主机地址,带端口
|
|
|
|
RemotePath string // 远程主机的存储路径
|
|
|
|
} |
|
|
|
|
|
|
|
@ -112,6 +112,7 @@ func (f *FileService) Upload(stream pb.FileUploadService_UploadFileServer, dirpa |
|
|
|
// 压缩文件
|
|
|
|
// 返回压缩包的名称
|
|
|
|
func (f *FileService) Compress(args *ZipBlock, reply *string) error { |
|
|
|
// fmt.Printf("compress args: %v\n", args)
|
|
|
|
// 启用日志
|
|
|
|
logger := util.NewProductionLogger() |
|
|
|
defer logger.Sync() |
|
|
|
@ -124,7 +125,7 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error { |
|
|
|
taskId := make(chan string) |
|
|
|
// 异步压缩
|
|
|
|
go func() { |
|
|
|
util.CompressToZip(zpFileName, realFilePath, args.Basepath, args.SelFile) |
|
|
|
util.CompressToZip(zpFileName, realFilePath, args.SelFile) |
|
|
|
taskId <- "arcok" |
|
|
|
// 日志输出
|
|
|
|
logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath)) |
|
|
|
@ -137,12 +138,9 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error { |
|
|
|
if strings.EqualFold(strings.ToLower(rest), "arcok") { |
|
|
|
// 合并为实际路径
|
|
|
|
remotePath := path.Join("/www/wwwroot", args.RemotePath, zpFileName) |
|
|
|
// 发送文件到远程服务器上
|
|
|
|
err := clientUploadFile(args.RemoteAdr, ziprl, remotePath) |
|
|
|
if err != nil { |
|
|
|
logger.Error("Compress", zap.String("msg", "上传文件到远程服务器失败"), zap.Error(err)) |
|
|
|
return nil |
|
|
|
} |
|
|
|
// 异步发送文件到远程服务器上
|
|
|
|
go clientUploadFile(args.RemoteAddr, ziprl, remotePath) |
|
|
|
|
|
|
|
// 返回压缩包名称
|
|
|
|
*reply = ziprl |
|
|
|
} |
|
|
|
@ -155,7 +153,7 @@ const chunkSize = 1024 * 1024 // 1MB |
|
|
|
// 客户端调用RPC传送文件的函数
|
|
|
|
// 传入zip的实际路径,远程的服务器带端口,远程文件存放路径
|
|
|
|
func clientUploadFile(remote string, filePath string, uploadPath string) error { |
|
|
|
|
|
|
|
fmt.Printf("remote: %s, filePath: %s, uploadPath: %s\n", remote, filePath, uploadPath) |
|
|
|
// 启用日志
|
|
|
|
logger := util.NewProductionLogger() |
|
|
|
defer logger.Sync() |
|
|
|
|