简体   繁体   中英

Edit files remotely on Windows Server 2012 with Python

How can I can connect remotely to a dedicated server with Windows Server 2012 R2 and edit or add files in C:/Users/$user/AppData/Roaming ?

I prefer to do this in Python if there is any solution.

In order to open the file on the remote server, use the UNC path:

fname = r'\\server_name\C$\Users\user_name\AppData\Roaming\file.txt'
with open(fname, 'r') as f:
    ...

Once you've opened the file, it's just like working with a file on your local file system. The one caveat is that you must be running your script from an account that has the appropriate privileges on the remote server. I usually do this by running it from a command prompt that I've opened as a user with elevated privileges.

I've used this method to do batch updates to hundreds of servers at a time.

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