Python Paramiko sftp

Source: Internet
Author: User

#!/usr/bin/env pythonImportParamikoImportSys,oshost='git' #IP地址或在hosts文件中绑定主机名IPUser='Root' #系统用户名Password='123' #密码s=Paramiko. Sshclient () #ssh实例s. Load_system_host_keys () #load本机的s. Set_missing_host_key_policy (Paramiko. Autoaddpolicy ()) #防止以前没连接过客户端主机, which means that there is no record of the corresponding client host in the known_hosts on the server and the error T= Paramiko. Transport ((host,22) #主机地址和端口t. Connect (username=user,password=password) #用户名和密码#pkey_file = '/root/.ssh/id_rsa ' # before the script starts, the public key of the user who generates the connection is Ssh-keygen, and the public key is ssh-copy-id-i [client user]@[ip address]#key = Paramiko. RSAKey.from.private_key_file (pkey_file) #使用私钥连接#T.connect (username=user,pkey=key) #使用用户名和key进行连接sftp=Paramiko. Sftpclient.from_transport (t) sftp.get ('/root/git.pdf','git.pdf'# The client's /root/git.pdf is routed to the current directory where the server-side script resides and is named git.pdfsftp.put ('para.py','/root/para_ssh.py') #将server脚本所在目录的 The para.py file to the client's /root/para_ssh.pys.close

Python Paramiko sftp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.