#!/usr/bin/env python
# encoding: utf-8

"""
@author: Will
"""

#
# import select
# import sys
# import socket
# import paramiko
# import os
#
#
# tran = paramiko.Transport(("192.168.11.130",22,))
# tran.start_client()
# tran.auth_password("root","1")
# chan = tran.open_session()
# chan.get_pty()
# chan.invoke_shell()
#
# while 1:
#     # print "123"
#     readable,writeable,error = select.select([chan,sys.stdin],[],[],1)
#     if chan in readable:
#         try:
#             x = chan.recv(1024)
#             if len(x) ==0:
#                 print '\r\n***EOF\r\n',
#                 break
#             sys.stdout.write(x)
#             sys.stdout.flush()
#         except socket.timeout:
#             pass
#
#     if sys.stdin in readable:
#         inp = sys.stdin.readline()
#         chan.sendall(inp)
#
# chan.close()
# tran.close()


# import select
# import sys
# import socket
# import paramiko
# import os
# import termios
# import tty
#
# tran = paramiko.Transport(("192.168.11.130",22,))
# tran.start_client()
# tran.auth_password("root","1")
# chan = tran.open_session()
# chan.get_pty()
# chan.invoke_shell()
#
# oldtty = termios.tcgetattr(sys.stdin)
#
# try:
#     tty.setraw(sys.stdin.fileno())
#     chan.settimeout(0.0)
#
#     while 1:
#         r,w,e = select.select([chan,sys.stdin],[],[],1)
#         if chan in r:
#             try:
#                 x = chan.recv(1024)
#                 if len(x) ==0:
#                     print "end"
#                     break
#                 sys.stdout.write(x)
#                 sys.stdout.flush()
#             except socket.timeout:
#                 pass
#         if sys.stdin in r:
#             x = sys.stdin.read(1)
#             if len(x)==0:
#                 break
#             chan.send(x)
# finally:
#     termios.tcsetattr(sys.stdin,termios.TCSADRAIN,oldtty)






# import paramiko
#
#
# #创建对象
# ssh = paramiko.SSHClient()
#
# #设置访问策略,默认拒绝所有不明的server,这里使用AutoAddPolicy()添加服务器到 L{HostKeys}对象,允许链接不在know_host文件中的主机,
# ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#
# #链接服务器
# ssh.connect(hostname="127.0.0.1",port=22,username="will",password="123123")
#
# #远程执行命令,执行结果会返回给stdin.stdout.stderr 三个变量
# stdin,stdout,stderr = ssh.exec_command("ls /")
#
# # 读取变量值 并赋值给变量result
# result = stdin.read()
#
# #关闭链接
# ssh.close()



# import paramiko
#
# #指定密钥文件
# privateKey = paramiko.RSAKey._from_private_key_file("/home/will/id_rsa")
#
# #创建对象
# ssh = paramiko.SSHClient()
#
# #设置访问策略,默认拒绝所有不明的server,这里使用AutoAddPolicy()添加服务器到 L{HostKeys}对象,允许链接不在know_host文件中的主机,
# ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#
# #链接服务器
# ssh.connect(hostname="127.0.0.1",port=22,username="will",pkey=privateKey)
#
# #远程执行命令,执行结果会返回给stdin.stdout.stderr 三个变量
# stdin,stdout,stderr = ssh.exec_command("ls /")
#
# # 读取变量值 并赋值给变量result
# print stdin.read()
#
# #关闭链接
# ssh.close()



# import paramiko
# hostInfo = ("127.0.0.1",22)
#
# trans =paramiko.Transport(hostInfo)
#
# trans.connect(username="will",password="123123")
#
# ssh = paramiko.SSHClient()
# ssh._transport = trans
#
# stdin,stdout,stderr = ssh.exec_command("ls /")
#
# print stdin.read()
# trans.close()

# import paramiko
#
# privateKey = paramiko.RSAKey._from_private_key_file("/home/will/id_rsa")
# hostInfo = ("127.0.0.1",22)
#
# trans =paramiko.Transport(hostInfo)
#
# trans.connect(username="will",pkey=privateKey)
#
# ssh = paramiko.SSHClient()
# ssh._transport = trans
#
# stdin,stdout,stderr = ssh.exec_command("ls /")
#
# print stdin.read()
# trans.close()




# 基于用户名密码上传下载
# import paramiko
#
# transport = paramiko.Transport(('127.0.0.1',22))
# transport.connect(username='will',password='1')
#
# sftp = paramiko.SFTPClient.from_transport(transport)
# # 上传文件至服务器 /tmp/test.py
# sftp.put('/tmp/location.py', '/tmp/test.py')
# # 将remove_path 下载到本地 local_path
# sftp.get('remove_path', 'local_path')
#
# transport.close()

# 基于公钥密钥上传下载
# import paramiko
#
# private_key = paramiko.RSAKey.from_private_key_file('/home/will/.ssh/id_rsa')
#
# transport = paramiko.Transport(('127.0.0.1', 22))
# transport.connect(username='wupeiqi', pkey=private_key )
#
# sftp = paramiko.SFTPClient.from_transport(transport)
# # 将location.py 上传至服务器 /tmp/test.py
# sftp.put('/tmp/location.py', '/tmp/test.py')
# # 将remove_path 下载到本地 local_path
# sftp.get('remove_path', 'local_path')
#
# transport.close()




# import MySQLdb
#
# #创建连接对象
# conn = MySQLdb.connect(host="127.0.0.1",user="root",passwd="123123",db="testdb")
# cu = conn.cursor()
# # 设置查询语句
# selectSQL = "select * from user"
# selectResult = cu.execute(selectSQL)
# #设置插入语句
# insertSQL = "insert INTO user(name,group) VALUES(%s,%s)"
# insertDate = [("user01","dba"),("user02","mgr"),("user03","staff")]
# insertResult = cu.execute(selectSQL)
# #设置更新语句
# updateSQl = "update user set name=%s where NAME =%s"
# updateData = ("newuser","user03")
# updateResult = cu.execute(selectSQL)
#
# #设置删除语句
# delSQl = "delete from user WHERE name=%s"
# delData = ("newuser")
# delResult = cu.execute(selectSQL)
#
#
# print cu.fetchall()
# conn.commit()
#
# cu.close()
# conn.close()




















































