Browse Source

修正获取目录

master
xyiege 4 months ago
parent
commit
03274297bf
  1. 22
      scagent/core/FileRpc.go

22
scagent/core/FileRpc.go

@ -45,7 +45,14 @@ type FileChunk struct {
// SendFile 接收文件信息(名称和大小) // SendFile 接收文件信息(名称和大小)
func (f *FileService) SendFileInfo(info FileInfo, reply *bool) error { func (f *FileService) SendFileInfo(info FileInfo, reply *bool) error {
// 创建保存文件的目录 // 创建保存文件的目录
if err := os.MkdirAll("received_files", 0755); err != nil { // if err := os.MkdirAll("received_files", 0755); err != nil {
// return err
// }
// 提取路径 /www/wwwroot/bidemo.com/BIU_20250918_183144.zip
dirPath := filepath.Dir(info.FileName)
// 创建目录
if err := os.MkdirAll(dirPath, 0755); err != nil {
return err return err
} }
@ -63,7 +70,11 @@ func (f *FileService) SendFileInfo(info FileInfo, reply *bool) error {
// SendFileChunk 接收文件块并写入文件 // SendFileChunk 接收文件块并写入文件
func (f *FileService) SendFileChunk(chunk FileChunk, reply *bool) error { func (f *FileService) SendFileChunk(chunk FileChunk, reply *bool) error {
filePath := filepath.Join("received_files", chunk.FileName) // filePath := filepath.Join("received_files", chunk.FileName)
fmt.Printf("recive file :%s", chunk.FileName)
// 合并为实际路径
// filePath := filepath.Join("received_files", chunk.FileName)
filePath := chunk.FileName
// 打开文件,使用追加模式 // 打开文件,使用追加模式
file, err := os.OpenFile(filePath, os.O_WRONLY, 0644) file, err := os.OpenFile(filePath, os.O_WRONLY, 0644)
@ -141,7 +152,9 @@ func clientUploadFile(remote string, filePath string, uploadPath string) error {
service := fmt.Sprintf("%v:%v", dstip, dport) service := fmt.Sprintf("%v:%v", dstip, dport)
client, err := rpc.Dial("tcp", service) client, err := rpc.Dial("tcp", service)
if err != nil { if err != nil {
panic(err) //panic(err)
fmt.Printf("连接到RPC服务器失败: %v", err)
return err
} }
defer client.Close() defer client.Close()
// 获取文件信息 // 获取文件信息
@ -169,7 +182,8 @@ func clientUploadFile(remote string, filePath string, uploadPath string) error {
defer file.Close() defer file.Close()
// 读取并发送文件块 // 读取并发送文件块
buffer := make([]byte, 4096) // 4KB块大小 chunkSize := 1 * 1024 * 1024 // 1MB
buffer := make([]byte, chunkSize) // 4KB块大小
reader := bufio.NewReader(file) reader := bufio.NewReader(file)
var offset int64 = 0 var offset int64 = 0

Loading…
Cancel
Save