简体   繁体   中英

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
2. Read the lines of the text file
3. Store the lines in a variable and be able to process the data.

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. 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. Are there any modules out there that I can install to achieve this process?

You can use powershell for this.

first Open powershell by admin previlage.

Enter this command

Enable-PSRemoting -Force

Enter this command also on both computer so they trust eachother.

Set-Item wsman:\\localhost\\client\\trustedhosts *

then restart winrm service on both pc by this command.

Restart-Service WinRM

test it by this command

Test-WsMan computername

for executing a Remote Command.

Invoke-Command -ComputerName COMPUTER -ScriptBlock { COMMAND } -credential USERNAME

for starting remote session.

Enter-PSSession -ComputerName COMPUTER -Credential USER

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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