在windows中的時候像windows用戶那樣做。
如果您無法在服務器上安裝其他軟件,則需要安裝驅動器,並與遠程文件(如本地文件)進行交互。
您提到您要連接的遠程服務器太多。爲什麼不選擇一個驅動器號,併爲需要連接的每臺服務器重新使用它?
使用net use
您可以從命令行進行掛載。
Syntax for net use
net use p: /delete:yes
net use p: \\remote_host\share_name password /user:domain\user
使用Python的subprocess包運行mount命令。 Subprocess tutor。
import subprocess
# Make sure the drive isn't mounted.
try:
subprocess.call('net use p: /delete:yes', shell=True)
except:
# This might fail if the drive wasn't in use.
# As long as the next net use works, we're good.
pass
for host in ("host1", "host2"):
# mount(map) the remote share.
subprocess.call('net use p: \\%s\share_name password /user:domain\user' % host, shell=True)
with open("p:\path\remote-file.txt", "r") as remote_file:
# do stuff
# dismount(map) the drive
subprocess.call('net use p: /delete:yes', shell=True)
(不要有窗戶框和網絡測試這個上。)
爲什麼不直接使用UNC路徑?只要您的帳戶有權限,只需寫入:\\ server_name \ $ [drive_letter] \ etc .. – 2015-03-30 17:50:17
除非您映射d驅動器,否則您將如何從您的本地Windows機器使用它? – Pankaj 2015-03-30 18:01:17