Skip to content

Commit

Permalink
并发上传目录
Browse files Browse the repository at this point in the history
  • Loading branch information
lingen committed Jan 7, 2023
1 parent a396bbe commit 1147999
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ssh/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"sync"

. "github.com/MrYZhou/outil/common"
// . "o/common"

. "github.com/MrYZhou/outil/file"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
Expand Down Expand Up @@ -274,10 +272,16 @@ func (c *Cli) UploadDir(base string, target string) {
c.SftpClient.MkdirAll(targetPath)
}
// 创建远程文件
for _, f := range list {
var wg sync.WaitGroup
for i, f := range list {
targetPath := strings.Replace(f, base, target, 1)
c.UploadFile(f, targetPath)
wg.Add(1)
go func(i int,f string,targetPath string) {
c.UploadFile(f, targetPath)
wg.Done()
}(i,f,targetPath)
}
wg.Wait()
}

/*
Expand Down

0 comments on commit 1147999

Please sign in to comment.