简体   繁体   English

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

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

I am trying to send a file from my PC to many servers to a specific folder in the server directory using one script, for keeping things simple, I am trying in the beginning to send one file to one server instead of many. 我试图使用一个脚本将文件从我的PC发送到许多服务器,并发送到服务器目录中的特定文件夹,为使操作简单起见,我尝试在一开始就将文件发送到一台服务器,而不是许多服务器。

I am already connected to a server using a key for authentication, so I do not need to use any login info in my code. 我已经使用密钥进行身份验证连接到服务器,因此不需要在代码中使用任何登录信息。 I have used the following: 我使用了以下内容:

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

I get the following Exception: 我收到以下异常:

AttributeError: "'Connection' object has no attribute '_transport_live'" in <bound method Connection.__del__ of <pysftp.Connection object at 0x0000000002E1F3C8>>

I have tried to insert the server port beside the IP address, it did not help as I get the same error. 我试图将服务器端口插入IP地址旁边,但并没有帮助,因为我遇到了同样的错误。

Use this 用这个

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

if you're still having problems change private_key to password 如果仍然有问题,请将private_key更改为password

check out the documentation 查看文档

http://pysftp.readthedocs.org/en/release_0.2.8/pysftp.html 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