[英]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
查看文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.