Skip to content

Commit

Permalink
Expose MaxShells as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
pecigonzalo committed Sep 1, 2015
1 parent 74bfc86 commit 3d70129
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func runMain() error {
cacert := flags.String("cacert", "", "ca certificate to validate against")
opTimeout := flags.Duration("op-timeout", time.Second*60, "operation timeout")
maxOpsPerShell := flags.Int("max-ops-per-shell", 15, "max operations per shell")
maxShells := flags.Int("max-shells", 10, "max shells per user")
flags.Parse(os.Args[1:])

var certBytes []byte
Expand All @@ -72,6 +73,7 @@ func runMain() error {
CACertBytes: certBytes,
OperationTimeout: *opTimeout,
MaxOperationsPerShell: *maxOpsPerShell,
MaxShells: *maxShells,
})
if err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions winrmcp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func doCopy(client *winrm.Client, config *Config, in io.Reader, toPath string) e
log.Printf("Copying file to %s\n", tempPath)
}

err := uploadContent(client, config.MaxOperationsPerShell, "%TEMP%\\"+tempFile, in)
err := uploadContent(client, config.MaxShells, config.MaxOperationsPerShell, "%TEMP%\\"+tempFile, in)
if err != nil {
return errors.New(fmt.Sprintf("Error uploading file to %s: %v", tempPath, err))
}
Expand All @@ -47,18 +47,21 @@ func doCopy(client *winrm.Client, config *Config, in io.Reader, toPath string) e
return nil
}

func uploadContent(client *winrm.Client, maxChunks int, filePath string, reader io.Reader) error {
func uploadContent(client *winrm.Client, maxShell int, maxChunks int, filePath string, reader io.Reader) error {
var err error
var piece = 0
var wg sync.WaitGroup
parallel := 4

if maxChunks == 0 {
maxChunks = 1
}

if maxChunks == 0 {
maxChunks = 10
}

// Create 4 Parallel workers
for p := 0; p < parallel; p++ {
for p := 0; p < maxShell; p++ {
done := make(chan bool, 1)
// Add worker to the WaitGroup
wg.Add(1)
Expand Down
1 change: 1 addition & 0 deletions winrmcp/winrmcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
CACertBytes []byte
OperationTimeout time.Duration
MaxOperationsPerShell int
MaxShells int
}

type Auth struct {
Expand Down

0 comments on commit 3d70129

Please sign in to comment.