SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import paramiko
  3. ip="10.100.1.200"
  4. ssh=paramiko.SSHClient()
  5. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  6. ssh.connect(ip,username="admin",password="pass")
  7.  
  8. text=open("conf")
  9.  
  10. for komut in text.readlines():
  11.  
  12.         stdin, stdout, stderror = ssh.exec_command(komut)
  13.         for line in stdout.readlines():
  14.                         print line.strip()
  15.  
  16.  
  17. ssh.close()
  18.  
  19. text.close()
  20.    
  21. Traceback (most recent call last):
  22.   File "./configmaker.py", line 13, in <module>
  23.     stdin, stdout, stderror = ssh.exec_command(str(komut.strip()))
  24.   File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 370, in exec_command
  25.     chan = self._transport.open_session()
  26.   File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 662, in open_session
  27.     return self.open_channel('session')
  28.   File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 764, in open_channel
  29.     raise e
  30. EOFError
  31.    
  32. import paramiko
  33.  
  34. if __name__ == "__main__":
  35.     ip = "127.0.0.1"
  36.     username = "admin"
  37.     password = "root"
  38.  
  39.     ssh = paramiko.SSHClient()
  40.     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  41.     ssh.connect(ip,username=username,password=password)
  42.     ssh_transport = ssh.get_transport()
  43.  
  44.     for command in ("ls /tmp", "date"):
  45.         chan = ssh_transport.open_session()
  46.         chan.exec_command(command)
  47.         exit_code = chan.recv_exit_status()
  48.         stdin = chan.makefile('wb', -1)         # pylint: disable-msg=W0612
  49.         stdout = chan.makefile('rb', -1)
  50.         stderr = chan.makefile_stderr('rb', -1)  # pylint: disable-msg=W0612
  51.         output = stdout.read()
  52.         print output
  53.    
  54. ssh = paramiko.SSHClient()
  55. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  56. host = str(host)
  57. user = 'root'
  58. pw = 'root123'
  59. ssh.connect(host, username=user, password=pw)
  60.  
  61. filepath = "conf"
  62. remote_path = "/root/qats_tool.tar"
  63.  
  64. sftp = ssh.open_sftp()
  65. sftp.put(filepath, remote_path)
  66.  
  67. command="./conf"
  68. stdin, stdout, stderr = ssh.exec_command(command)
  69. sftp.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top