- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
那么,如何使用 WinRM + Python 将文件上传到 Windows 计算机?
最佳答案
import base64
class WinRMUtil:
def __init__(self, session):
self.session = session
def upload_file(local_filename, remote_filename):
file = open(local_filename, 'rt')
text = file.read()
text = text.replace('\n', '\r\n')
file.close()
self._create_remote_file(remote_filename, text)
def _create_remote_file(self, remote_filename, text):
step = 400
utf8 = text.encode("utf8")
for i in range(0, len(utf8), step):
self._do_put_file(remote_filename, utf8[i:i + step])
def _do_put_file(self, location, contents):
# adapted/copied from https://github.com/diyan/pywinrm/issues/18
p1 = """
$filePath = "{}"
$s = @"
{}
"@""" % (location, base64.b64encode(contents).decode('utf8'))
p2 = """
$data = [System.Convert]::FromBase64String($s)
add-content -value $data -encoding byte -path $filePath
"""
ps_script = p1 + p2
encoded_ps = base64.b64encode(ps_script.encode('utf_16_le')).decode('utf8')
rs = self.session.run_cmd('powershell -encodedcommand {0}'.format(encoded_ps))
if rs.status_code == 1:
self._log.warning(rs.std_err)
return None
return rs.std_out
关于python - 如何使用 winrm+Python 将文件上传到 Windows 机器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48376680/
我正在尝试使用 powershell System.Management.Automation dll 访问远程系统服务的详细信息。 当我执行下面的代码连接到远程系统时,我遇到了错误: 代码片段: s
所以我已经在几种不同的变体下对此进行了测试。我有一个装有 Windows 2008 R2 服务器并安装了 RHEL6 和 Python2.6 的实验室。我能够使用 ansible 作为远程进入 Win
我想将 WinRM 与 https 传输结合使用。我购买了 Comodo 证书(错误状态是我不能使用自签名证书),其主题与我的 Windows 10 计算机(未加入域)的 FQDN(系统中的完整计算机
这是当我尝试连接到远程计算机上的 Powershell 时发生的情况: PS C:\Users\Jonathan> Test-WSMan -ComputerName 54.228.XX.XX Test
我正在尝试在几台机器上设置远程管理。我可以从我的计算机在远程机器上成功执行命令,但我不希望任何人能够这样做。 我尝试在远程计算机上设置受信任的主机,并重新启动服务,但它似乎没有做任何事情。 例如,在远
New-PSSession 在使用服务器的主机名时不起作用,但在使用 IP 时起作用。本地和远程计算机都在同一域中。 PS C:\Windows\system32> new-PSSession -Co
我正在尝试使用公司网络中的公司服务器创建 Enter-PSSession。我可以 RDC 到服务器,ping 服务器,还可以使用 Get-Service -ComputerName DBServer
我无法在 python 脚本中获取 WinRM session 。 环境 ad-dns.test.com - Windows 2012 AD and DNS Server box88.test.
我看过很棒的文章 PowerShell 2.0 远程处理指南:第 8 部分 - 远程处理方案和故障排除 http://www.ravichaganti.com/blog/?p=1181 我有这个问题:
当我尝试在远程计算机上获取服务信息时,出现 WINRM 错误。 PS C:\Windows\system32> invoke-command -computername Node1 -ScriptB
我们的一些服务器 (W2K8 R2) 上周移到了云端,一旦完成,我的 powerswell 脚本开始失败(之前工作正常),在尝试建立连接的线路上抛出异常, $ExSession = New-PSSes
我可以使用 WINRM 将二进制文件推送到远程主机 Windows 上吗?如果没有,是否有任何其他机制允许我在远程主机上推送二进制文件。 最佳答案 我想我找到了解决方案。 #include #inc
我在 Windows 7 64 位上使用 ChefDK 0.3.5。我在尝试使用 Chef 和 WinRM 执行远程服务器上的 chef-client 命令。我发出的命令如下: C:\U\user1>
我有一些想在Windows主机上运行的Ansible剧本。我遵循了各种Ansible指南来设置WinRM,并且它们运行良好,但是默认设置非常不安全,我希望可以进行更多生产。但是,有关如何执行此操作的说
当我运行时 knife bootstrap windows winrm -x Administrator -P "" -r "role[myrole]" 我的实例在 vpc 中,我已经附加了 eip
要从远程机器在机器上运行 powershell 命令,我们必须将远程机器添加到主机的受信任主机列表中。 我正在使用以下命令将机器 A 添加到机器 B 的受信任主机: winrm set winrm/c
我正在使用 ansible vsphere_guest 模块在 VMWare 环境中启动基本 Windows 机器。在我的剧本中,为此我设置了 Hosts: 127.0.0.1 connection:
我正在使用这个 code在服务器上执行远程代码(MSI 安装)。通过脚本传递双引号是行不通的。我尝试了下面给出的两种变体(#3和#4)以及输出。 输入#1(测试命令中双引号的简单案例) powersh
我使用了现有的 VNET、资源组、子网供加壳程序用来创建虚拟机并从中获取镜像。我从市场上获取了 Windows 镜像。加壳程序启动了一个虚拟机,但在连接到它时超时。我在下面包含了我的 JSON 文件
connection { type = "winrm" user = "testadmin" password = "Password1234!" host = azurerm_pub
我是一名优秀的程序员,十分优秀!