|
|
@ -9,6 +9,7 @@ import ( |
|
|
"os" |
|
|
"os" |
|
|
"path" |
|
|
"path" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
|
|
|
"scagent/config" |
|
|
pb "scagent/proto/fileupload" |
|
|
pb "scagent/proto/fileupload" |
|
|
"scagent/util" |
|
|
"scagent/util" |
|
|
"strings" |
|
|
"strings" |
|
|
@ -16,6 +17,7 @@ import ( |
|
|
|
|
|
|
|
|
"go.uber.org/zap" |
|
|
"go.uber.org/zap" |
|
|
"google.golang.org/grpc" |
|
|
"google.golang.org/grpc" |
|
|
|
|
|
"google.golang.org/grpc/credentials/insecure" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// FileService 提供文件传输服务
|
|
|
// FileService 提供文件传输服务
|
|
|
@ -131,7 +133,7 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error { |
|
|
logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath)) |
|
|
logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath)) |
|
|
}() |
|
|
}() |
|
|
// ZIP 文件的实际路径
|
|
|
// ZIP 文件的实际路径
|
|
|
ziprl := path.Join(args.Basepath, "/sync_zips", zpFileName) |
|
|
ziprl := path.Join(config.G.FilePath, "/sync_zips", zpFileName) |
|
|
// zip 创建成功后
|
|
|
// zip 创建成功后
|
|
|
rest := <-taskId |
|
|
rest := <-taskId |
|
|
// 如果压缩包生成成功以后再执行
|
|
|
// 如果压缩包生成成功以后再执行
|
|
|
@ -153,7 +155,7 @@ const chunkSize = 1024 * 1024 // 1MB |
|
|
// 客户端调用RPC传送文件的函数
|
|
|
// 客户端调用RPC传送文件的函数
|
|
|
// 传入zip的实际路径,远程的服务器带端口,远程文件存放路径
|
|
|
// 传入zip的实际路径,远程的服务器带端口,远程文件存放路径
|
|
|
func clientUploadFile(remote string, filePath string, uploadPath string) error { |
|
|
func clientUploadFile(remote string, filePath string, uploadPath string) error { |
|
|
fmt.Printf("remote: %s, filePath: %s, uploadPath: %s\n", remote, filePath, uploadPath) |
|
|
// fmt.Printf("remote: %s, filePath: %s, uploadPath: %s\n", remote, filePath, uploadPath)
|
|
|
// 启用日志
|
|
|
// 启用日志
|
|
|
logger := util.NewProductionLogger() |
|
|
logger := util.NewProductionLogger() |
|
|
defer logger.Sync() |
|
|
defer logger.Sync() |
|
|
@ -164,7 +166,9 @@ func clientUploadFile(remote string, filePath string, uploadPath string) error { |
|
|
|
|
|
|
|
|
// 连接到服务器
|
|
|
// 连接到服务器
|
|
|
service := fmt.Sprintf("%v:%v", dstip, dport) |
|
|
service := fmt.Sprintf("%v:%v", dstip, dport) |
|
|
conn, err := grpc.NewClient(service) |
|
|
fmt.Printf("service: %s\n", service) |
|
|
|
|
|
conn, err := grpc.Dial(service, grpc.WithTransportCredentials(insecure.NewCredentials())) // 使用安全连接
|
|
|
|
|
|
// conn, err := grpc.NewClient(service)
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
logger.Error("clientUploadFile", zap.String("msg", "无法连接到服务器"), zap.Error(err)) |
|
|
logger.Error("clientUploadFile", zap.String("msg", "无法连接到服务器"), zap.Error(err)) |
|
|
return err |
|
|
return err |
|
|
|