Browse Source

修改为安全传递

master
xyiege 4 months ago
parent
commit
e9ca3bdff9
  1. 10
      scagent/core/FileRpc.go

10
scagent/core/FileRpc.go

@ -9,6 +9,7 @@ import (
"os"
"path"
"path/filepath"
"scagent/config"
pb "scagent/proto/fileupload"
"scagent/util"
"strings"
@ -16,6 +17,7 @@ import (
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
// FileService 提供文件传输服务
@ -131,7 +133,7 @@ func (f *FileService) Compress(args *ZipBlock, reply *string) error {
logger.Info("压缩文件", zap.String("filename", zpFileName), zap.String("path", realFilePath))
}()
// ZIP 文件的实际路径
ziprl := path.Join(args.Basepath, "/sync_zips", zpFileName)
ziprl := path.Join(config.G.FilePath, "/sync_zips", zpFileName)
// zip 创建成功后
rest := <-taskId
// 如果压缩包生成成功以后再执行
@ -153,7 +155,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)
// fmt.Printf("remote: %s, filePath: %s, uploadPath: %s\n", remote, filePath, uploadPath)
// 启用日志
logger := util.NewProductionLogger()
defer logger.Sync()
@ -164,7 +166,9 @@ func clientUploadFile(remote string, filePath string, uploadPath string) error {
// 连接到服务器
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 {
logger.Error("clientUploadFile", zap.String("msg", "无法连接到服务器"), zap.Error(err))
return err

Loading…
Cancel
Save