2015-03-30 197 views
0

我想使用我的python腳本從遠程windows 2008 R2服務器下載/上傳文件。問題是我不想在我的Windows服務器上安裝任何額外的東西。我想用我的正常登錄憑據來實現這一點。使用python下載/上傳文件到遠程windows服務器

下面是不同的方法,我聽到的:

  1. 使用的paramiko SSH:但使用此,我們必須對遙控盒,這是我不想做安裝SSH服務。
  2. 使用python wmi模塊:但我想它沒有從遠程服務器下載文件的功能。
  3. 在您的本地盒子上掛載驅動器:也不想這樣做,因爲會有很多我想連接的機器。
  4. 使用winscp:我想它也需要SSH?
  5. 面料:聽說過,不知道它的先決條件是什麼。

有沒有其他方法可以實現這個目標?

+0

爲什麼不直接使用UNC路徑?只要您的帳戶有權限,只需寫入:\\ server_name \ $ [drive_letter] \ etc .. – 2015-03-30 17:50:17

+0

除非您映射d驅動器,否則您將如何從您的本地Windows機器使用它? – Pankaj 2015-03-30 18:01:17

回答

1

在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) 

(不要有窗戶框和網絡測試這個上。)

相關問題