|
|
@ -33,6 +33,7 @@ import ( |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"runtime" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
@ -93,10 +94,15 @@ func handleResponse(reader io.Reader, ip string) error { |
|
|
|
log.Printf("Received file list: %v", fileList) |
|
|
|
|
|
|
|
for _, file := range fileList { |
|
|
|
if runtime.GOOS != "windows" && containsBackslash(file.WritePath) { |
|
|
|
file.WritePath = filepath.FromSlash(file.WritePath) |
|
|
|
} |
|
|
|
checkpath := filepath.Join(receiveDir, file.WritePath) |
|
|
|
if err := os.MkdirAll(checkpath, 0755); err != nil { |
|
|
|
return fmt.Errorf("failed to create directory: %v", err) |
|
|
|
|
|
|
|
if !libs.PathExists(checkpath) { |
|
|
|
os.MkdirAll(checkpath, 0755) |
|
|
|
} |
|
|
|
|
|
|
|
if !file.IsDir { |
|
|
|
go downloadFile(file.Path, checkpath, ip) |
|
|
|
} |
|
|
@ -105,6 +111,11 @@ func handleResponse(reader io.Reader, ip string) error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
// containsBackslash 检查字符串中是否包含反斜杠
|
|
|
|
func containsBackslash(s string) bool { |
|
|
|
return filepath.Separator == '\\' && filepath.VolumeName(s) == "" |
|
|
|
} |
|
|
|
|
|
|
|
// downloadFile 下载单个文件
|
|
|
|
func downloadFile(filePath string, checkpath string, ip string) error { |
|
|
|
url := fmt.Sprintf("http://%s:56780/localchat/servefile?path=%s", ip, filePath) |
|
|
|