将文件发送到服务器中的特定路径

时间:2016-04-21 23:33:02

标签: python file transfer

我正在尝试使用一个脚本将文件从我的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地址旁边插入服务器端口,因为我收到同样的错误,但没有帮助。

1 个答案:

答案 0 :(得分:0)

使用此

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

相关问题