paramiko(1) use

ssh connection

>>> import paramiko
>>> paramiko.util.log_to_file('paramiko.log')
>>> ssh=paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect(hostname='192.168.0.88',username='root',password='123456',timeout=5)
>>> stdin,stdout,stderr=ssh.exec_command('echo "OK"')
>>> out=stdout.read(),stderr.read()
>>> print out
('OK\n', '')
>>> ssh.close()

 send file

 

>>> t=paramiko.Transport(('192.168.0.88',22))              
>>> t.connect(username='root',password='123456')
>>> sftp=paramiko.SFTPClient.from_transport(t)
>>> sftp.get('/etc/passwd','passwd')
>>> sftp.put('/root/passwd','/root/passwd1')
<SFTPAttributes: [ size=926 uid=0 gid=0 mode=0100644 atime=1472969310 mtime=1472969310 ]>

 Upload files as short links

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326562001&siteId=291194637