簡體   English   中英

將文件發送到服務器中的特定路徑

[英]Send a file to a specific path in a server

我試圖使用一個腳本將文件從我的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地址旁邊,但並沒有幫助,因為我遇到了同樣的錯誤。

用這個

sftp.Connection(host="your_host", port="your_port", username="user_name", private_key="private_key")

如果仍然有問題,請將private_key更改為password

查看文檔

http://pysftp.readthedocs.org/en/release_0.2.8/pysftp.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM