我想從我的PC發送文件到許多服務器到服務器目錄中的特定文件夾使用一個腳本,爲了保持簡單,我想在開始時發送一個文件到一臺服務器而不是很多。發送文件到服務器中的特定路徑
我已經連接到使用密鑰進行身份驗證的服務器,所以我不需要在我的代碼中使用任何登錄信息。我已經使用了以下內容:
import pysftp as sftp
def Filetransfer():
try:
s = sftp.Connection(host='IP address')# this is where the server ip address is inserted
remotepath='/xx/yy/file.txt'# where my file will be transferred to
localpath='C:/Users/David/Desktop/file.txt'# this is the file location in my PC
s.put(localpath,remotepath)
s.close()
except Exception, e:
print str(e)
Filetransfer()
我得到以下異常:
AttributeError: "'Connection' object has no attribute '_transport_live'" in <bound method Connection.__del__ of <pysftp.Connection object at 0x0000000002E1F3C8>>
我試圖插入IP地址旁邊的服務器端口,它並沒有幫助,因爲我得到同樣的錯誤。
你絕對確保你使用正確的問題變化密碼並通過開放端口連接? – danidee
hej danidee,我使用Pulse Secure SW連接到服務器。 Se這個https://www.pulsesecure.net和登錄是通過輸入我的用戶名和密鑰生成器完成的。我可以導航到服務器並使用SecureFX工具連接到每個服務器。因此,我需要的不是從我的PC中手動將文件拖動到服務器中的特定文件夾,而是自動執行。我不這應該是與上面的代碼有問題,但我不明白爲什麼我會得到這個錯誤:(即使您從另一個程序登錄到服務器,但仍然沒有辦法你的python( – ChakEL
)腳本可以知道你已經登錄。所以你需要在你的腳本中使用登錄信息也 – danidee