Python Learning Record----module Paramiko

Source: Internet
Author: User

Paramiko

first, Installation

pip3.5 Install paramikopip3.5 Install Pycrypto
1 #pycrypto, Since the Paramiko module is internally dependent on pycrypto, download the installation first Pycrypto2  3 #Download and install Pycrypto4wget http://xxxxxx/pycrypto-2.6.1. tar.gz5TAR-XVF pycrypto-2.6.1. tar.gz6CD pycrypto-2.6.17 python setup.py build8 python setup.py Install9  Ten #Enter the Python environment, import crypto to check if the installation was successful one   a #Download and install Paramiko -wget http://xxxxxx/paramiko-1.10.1. tar.gz -TAR-XVF paramiko-1.10.1. tar.gz theCD paramiko-1.10.1 - python setup.py build - python setup.py Install -   + #Enter the Python environment, import Paramiko to check if the installation was successful

Ii. description

Paramiko powerful commands, can file

third, examples:

1. Command version: password, KEY

1 ImportParamiko2 3SSH =paramiko. Sshclient ()4 Ssh.set_missing_host_key_policy (paramiko. Autoaddpolicy ())5Ssh.connect ('hostname', 22,'username','Password')6stdin, stdout, stderr = Ssh.exec_command ('DF')7 PrintStdout.read ()8 ssh.close ();9 Ten ???????????????????????????????????? one ## #基于key a #-*-encoding:utf8-*- -  - ImportParamiko thePrivate_key_path="/users/tf/.ssh/id_rsa" -  -Key =paramiko. Rsakey.from_private_key_file (private_key_path) -SSH =paramiko. Sshclient () + Ssh.set_missing_host_key_policy (paramiko. Autoaddpolicy ()) -Ssh.connect ("192.168.1.1", 22,'username', Key) +stdin, stdout, stderr = Ssh.exec_command ("DF") aresult = Ssh.exec_command ("ifconfig") at Print(stdout.read ()) - Print(result[1].read ()) -  -Ssh.close ()

2. Document Get\put

Password:

1 ImportParamiko2 3t = paramiko. Transport (("ipaddr", 22))4T.connect (username='UUU', password='123')5SFTP =paramiko. Sftpclient.from_transport (t)6Sftp.put ('/tmp/test.py','/tmp/test.py') 7 ##下载8Sftp.get ('file','file')9T.close ()

Generate Key:ssh-key-gen

Using key

1 #-*-encoding:utf8-*-2 3 ImportParamiko4 5Pravie_key_path ="/users/xx/.ssh/id_rsa"6Key =paramiko. Rsakey.from_private_key_file (pravie_key_path)7 8t = paramiko. Transport (('192.168.1.111', 22))9T.connect (username='xx', pkey=Key)Ten  oneSFTP =paramiko. Sftpclient.from_transport (t) aSftp.get ('/tmp/ubuntu.txt','/tmp/test4.py')#Download -Sftp.put ("/tmp/learn_corde_05.rtf","/tmp/learn_corde.rtf")##上传 -T.close ()

Python Learning Record----module Paramiko

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.