masterzen / winrm

Command-line tool and library for Windows remote command execution in Go
Apache License 2.0
425 stars 129 forks source link

getting error 413 - RunWithContextWithString #156

Closed Dmaddu closed 10 months ago

Dmaddu commented 10 months ago

Getting the 413 error with the below command

stdout, stderr, _, err := client.RunWithContextWithString(context.Background(), command, "")

the size of the "command" is ~10MB.

masterzen commented 10 months ago

It's because WinRM is an envelope based protocol, where each message has a size limit (see WinRM config parameter MaxEnvelopeSizekb in https://learn.microsoft.com/en-us/windows/win32/winrm/installation-and-configuration-for-windows-remote-management#maxenvelopesizekb, whose default is 150kb).

This project is not made to "upload" commands to the remote machine, projects like https://github.com/jbrekelmans/go-winrm might be better for your use case.

kke commented 10 months ago

If you want to transfer large files, you need to do it in pieces.

One way to do this is to use a powershell scriptlet that keeps reading stdin and writes to a file, then you can pretty much just io.Copy(cmd.Stdin, src); cmd.Stdin.Close(). It's not very fast and there are several pitfalls.

WinRM is not a great protocol.