简体   繁体   中英

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.

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.

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

check out the documentation

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM