mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-12-09 20:05:54 +08:00
fix: 解决 sftp 上传大文件失败的问题 (#1294)
This commit is contained in:
parent
95e1c73ced
commit
97774c88d5
1 changed files with 12 additions and 5 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
|
@ -75,11 +75,18 @@ func (s sftpClient) Upload(src, target string) (bool, error) {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
defer dstFile.Close()
|
defer dstFile.Close()
|
||||||
ff, err := io.ReadAll(srcFile)
|
|
||||||
if err != nil {
|
reader := bufio.NewReaderSize(srcFile, 128*1024*1024)
|
||||||
return false, err
|
for {
|
||||||
|
chunk, err := reader.Peek(8 * 1024 * 1024)
|
||||||
|
if len(chunk) != 0 {
|
||||||
|
_, _ = dstFile.Write(chunk)
|
||||||
|
_, _ = reader.Discard(len(chunk))
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, _ = dstFile.Write(ff)
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue