如何从本地python脚本在远程windows服务器中写入文件?

问题描述:

我想使用的网络驱动器的概念写在远程Windows服务器上的文件,但没能找到网络位置:如何从本地python脚本在远程windows服务器中写入文件?

z = open("\\\\xxxxxxxx\Program Files\abc.txt") 
z.write('This is a test\n') 

请给我建议的替代方案。

+2

【如何写串的可能的复制在python文字,而不必转义他们?](http://stackoverflow.com/questions/4703516/how-to-write-string-literals-in-python-without-having-to-escape-them) –

+0

“失败找到网络位置“你怎么知道?发布任何错误消息。 – DBedrenko

使用Paramiko模块的Python为创建SFTP会话,那么你可以传输文件或创建并写入到远程或远程到本地

试试这个:

from os import os.path 

filename = 'abc.txt' 
# use forward slash instead of back slash 
path = '//xxxxxxxx/Program Files/' 
outputfile = os.path.join(path, filename) 
output = open(outputfile, 'w')