#! /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 ()