Paramiko for Python Automated operations Development (Remote batch Management Server)

Source: Internet
Author: User

A: Introduction

Paramikois to usepythonlanguage to write a module that followsSSH2protocol that supports the connection of remote servers in an encrypted and authenticated manner. it only needs to be installed locally on the appropriate software (pythonas wellPycrypto), there is no configuration requirement for remote servers, and it is particularly helpful to connect multiple servers with complex connection operations.

Two: Installation method

   installationParamikoThere are two prerequisites,pythonand another namedPycryptothe module. the only trouble is to installPycrypto, you need toGCCLibrary compilation, if notGCCthe library will make an error, causingPycryptoas wellParamikoUnable to install. In the installation process, encountered an error, Baidu can find the basic solution!

following to + bit of Windows 7 as an example, explain Paramiko the installation process

1 : Install python 2.2 The above version is OK, I am using 2.7 d:\programfiles\python27 .

2: Determine if the local installationGCC, and inPATHvariables can be found, if not, can be usedWindowsversion ofGCC, i.e.MinGW,:http://sourceforge.net/projects/mingw/, and then run the downloadedEXEfile for network installation, assuming the directory isC:\mingw, inPATHJoin inC:\mingw\bin, and in D:\ProgramFiles\Python27\lib\distutilsunder Create a new name isdistutils.cfgthe file, fill in:

[Build]
Compiler=mingw32

3 : Download Pycrypto, installation package See the annex to this article

installation Pycrypto:

· Unzip

· Enter the extracted directory under DOS, run

D:\ProgramFiles\Python27\python.exe setup.py Build
D:\ProgramFiles\Python27\python.exe setup.py Install

· installation Test

Run Python.exe , at the prompt, enter:

Import Crypto

If no error message appears, the description Crypto Installation Successful

4 : Download Paramiko , the address is http://www.lag.net/paramiko/, installation package see the annex to this article

· Unzip

·           in dos enter into the extracted directory, run

D:\ProgramFiles\Python27\python.exe setup.py Build
D:\ProgramFiles\Python27\python.exe setup.py Install

· test Paramiko

Run Python.exe , at the prompt, enter:

Import Paramiko

If no error message appears, the description Paramiko The installation succeeds, as for the output of my computer:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/83/F7/wKioL1eCETGQ2PY8AAM2CF3OdoE317.bmp "title=" 2.bmp " alt= "Wkiol1ecetgq2py8aam2cf3odoe317.bmp"/>

Three: Program call

#从widnows端远程下载linux服务器上的文件t = Paramiko. Transport ((Ip,port)) T.connect (username=username,password=password) sftp = Paramiko. Sftpclient.from_transport (t) remotepath= '/cpic/jtvp/files/alarm/cpic_p17.log ' localpath= ' C:/CPIC_P17.log ' Sftp.get (RemotePath, localpath) print "---> Download successful" t.close ()----------------------------------------program output:---> The download succeeded in viewing the local directory, and the file was actually downloaded.
#上传文件到远程服务器, t= Paramiko. Transport ((Ip,port)) T.connect (username=username,password=password) sftp = Paramiko. Sftpclient.from_transport (t) remotepath= '/cpic/jtvp/files/alarm/spider.txt ' localpath= ' C:/spider.txt ' Sftp.put ( Localpath,remotepath) print "---> Upload successful" t.close ()----------------------------------------program output:---> Upload successfully telnet to the Linux server to check if the upload was successful.

With these operations, the batch management of Linux servers becomes very simple and provides the conditions for subsequent automated operations. Can be automated release, automated System information collection, alarm log collection, application log scanning and so on, and then call the alarm interface, triggering alarm, make operation more easy and efficient!






This article is from the "Reminder Flower Rain" blog, please make sure to keep this source http://chenwen.blog.51cto.com/771416/1815210

Paramiko for Python Automated operations Development (Remote batch Management Server)

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.