Package to execute commads on remote Windows, do file copy to the remote machine
Project description
winrmcp
A Python library to execute remote commands on Windows (cmd.exe and PowerShell), and to transfer files.
This is a thin wrapper on top of excellent pywinrm.
For file transfer, we use the same method as in Go package winrmcp.
Installation
pip install winrmcp
Quick start
from winrmcp import Client
client = Client('my-windows-machine.com', auth=('CleverUser', 'cleverPassword'))
with client.shell() as shell:
out, _ = shell.check_cmd(['ipconfig', '/all'])
print(out)
script = """$strComputer = $Host
Clear
$RAM = WmiObject Win32_ComputerSystem
$MB = 1048576
"Installed Memory: " + [int]($RAM.TotalPhysicalMemory /$MB) + " MB" """
out, _ = shell.check_ps(script)
print(out)
client.copy('/home/mike/temp/build.bat', '%TEMP%\\build.bat')
with client.shell() as shell:
shell.check_call('cmd.exe', '/k', '%TEMP%\\build.bat)
API
Client
Client extends winrm.Session to provide Client.shell context-manager that opens remote shell.
See documentaiotn of pywinrm for the expected parameters.
Client.shell() - creates a new context-managed shell, returns intsance of Shell.
Client.copy(local_file, remote_file) - copies the content of local file local_file to the remote machine as remote_file.
Note that local_file can be a file-like object, having read method returning bytes.
Shell
Shell represent the shell running on the remote Windows machine. You can get an instance of this class by
calling shell() on a Client instance.
Shell.cmd(command, *args) - runs a command in remote CMD.EXE shell. Returns winrm.Response instance, see docs there.
Shell.ps(script) - runs a script in remote PowerShell shell. Returns winrm.Response instance, see docs there.
Shell.check_cmd(command, *args) - runs a command in remote CMD.EXE shell. Returns a tuple of stdout and stderr strings. If remote command
return non-zero code, raises ShellCommandError exception.
Shell.check_ps(script) - runs a script in remote PowerShell shell. Returns a tuple of stdout and stderr strings. If remote command
return non-zero code, raises ShellCommandError exception.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file winrmcp-0.0.3-py3-none-any.whl.
File metadata
- Download URL: winrmcp-0.0.3-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c87448fcf8d816b3c05364c20f3278700fe5ff6e68d6d7a3006ce38b5dc8b8e
|
|
| MD5 |
0789d6de7bd0234534db073bbcb21387
|
|
| BLAKE2b-256 |
c543a75678986d7da2b81eef34e84b69e4b7f3deb7c3e1b315e01b5a26403f7f
|