Use of python SSH in windows-paramiko Module

Source: Internet
Author: User

 

 

#! /Usr/bin/python import paramikoserver_ip = '2017. 168. *. * 'server _ user = 'your _ user' server _ passwd = 'your _ password' server _ port = 22def ssh_connect (): ssh = paramiko. SSHClient () ssh. set_missing_host_key_policy (paramiko. autoAddPolicy () ssh. connect (server_ip, server_port, server_user, server_passwd) return ssh def ssh_disconnect (client): client. close () def exec_cmd (command): ''' windows client remotely executes commands on linux Server '''Stdin, stdout, stderr = ssh.exe c_command (command) err = stderr. readline () out = stdout. readline () if! = Err: print command: + command + exec failed! ERROR: + err return true, err else: print command: + command + exec success. def win_to_linux (localpath, remotepath): ''' windows uploads files to the linux server. localpath is the absolute path of the local file. For example, D: est. py remotepath is the absolute path for storing uploaded files on the server, rather than a directory. For example:/tmp/my_file.txt ''' client = paramiko. transport (server_ip, server_port) client. connect (username = server_user, password = server_passwd) sftp = paramiko. SFTPClient. from_transport (client) sftp. put (localpath, remotepath) client. close () def linux_to_win (localpath, remotepath): ''' download the file from the linux server to the local localpath is the absolute path of the local file. For example, D: est. py remotepath is the absolute path for storing uploaded files on the server, rather than a directory. For example:/tmp/my_file.txt ''' client = paramiko. transport (server_ip, server_port) client. connect (username = server_user, password = server_passwd) sftp = paramiko. SFTPClient. from_transport (client) sftp. get (remotepath, localpath) client. close ()


 

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.