简体   繁体   English

Python:在Windows上打开和读取远程文本文件

[英]Python: Open and read remote text files on Windows

Im trying to find a module that will allow me to run a script locally that will: 我试图找到一个模块,使我可以在本地运行脚本,该脚本将:
1. Open a text file on a remote Windows Machine 1.在远程Windows计算机上打开一个文本文件
2. Read the lines of the text file 2.阅读文本文件的行
3. Store the lines in a variable and be able to process the data. 3.将行存储在变量中,并能够处理数据。

This is absolutely no problem on a Linux machine via SSH, but I have no clue what module to use for a remote Windows machine. 在通过SSH的Linux机器上,这绝对没有问题,但是我不知道要为远程Windows机器使用哪个模块。 I can connect no problem and run commands on a remote Windows machine via WMI ,but WMI does not have a way to read/write to files. 我不能连接任何问题,也可以通过WMI在远程Windows机器上运行命令,但是WMI无法读取/写入文件。 Are there any modules out there that I can install to achieve this process? 我可以安装任何模块来实现此过程吗?

You can use powershell for this. 您可以为此使用powershell。

first Open powershell by admin previlage. 首先通过管理员权限打开powershell。

Enter this command 输入此命令

Enable-PSRemoting -Force Enable-PSRemoting-强制

Enter this command also on both computer so they trust eachother. 在两台计算机上也输入此命令,以便他们彼此信任。

Set-Item wsman:\\localhost\\client\\trustedhosts * 设置项wsman:\\ localhost \\ client \\ trustedhosts *

then restart winrm service on both pc by this command. 然后通过此命令在两台PC上重新启动winrm服务。

Restart-Service WinRM 重启服务WinRM

test it by this command 通过此命令对其进行测试

Test-WsMan computername Test-WsMan计算机名

for executing a Remote Command. 用于执行远程命令。

Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME 调用命令-计算机名计算机-脚本块{命令}-凭据用户名

for starting remote session. 用于启动远程会话。

Enter-PSSession -ComputerName COMPUTER -Credential USER Enter-PSSession -ComputerName计算机-凭据用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM