Guest User

Untitled

a guest
May 18th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #!/usr/bin/python3.6
  2.  
  3. import paramiko
  4. import paramiko
  5.  
  6. from paramiko import client
  7. class ssh:
  8. client = None
  9.  
  10. def __init__(self, address, username, password):
  11. print("Connecting to server.")
  12. self.client = client.SSHClient()
  13. self.client.set_missing_host_key_policy(client.AutoAddPolicy())
  14. self.client.connect(address,
  15. username = username,
  16. password = password,
  17. look_for_keys=False)
  18.  
  19. def sendCommand(self,
  20. command):
  21. if(self.client):
  22. stdin, stdout, stderr = self.client.exec_command(command)
  23.  
  24. output = []
  25. while not stdout.channel.exit_status_ready():
  26. portion = stdout.readlines()
  27. # print(portion)
  28. if len(portion) > 0:
  29. output.append(portion)
  30. result = self.output_to_string(output)
  31. return result
  32. else:
  33. raise Exception("Connection not opened.")
  34.  
  35. def output_to_string(self, output):
  36. result = ""
  37. for line in output:
  38. for el in line:
  39. # result += str(line, "utf8")
  40. result += el
  41. return result
  42.  
  43. #!/usr/bin/python3.6
  44.  
  45. import ssh_own
  46. import os
  47.  
  48. home = os.environ["HOME"]
  49.  
  50. ssh_client = ssh_own.ssh("ip", "username", "password")
  51. ftp_client = ssh_client.client.open_sftp()
  52. ftp_client.put("/home/localuser/README.md", "/home/username/README.md")
  53. ftp_client.close()
  54.  
  55. Connecting to server.
  56. Traceback (most recent call last):
  57. File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 103, in __init__
  58. server_version = self._send_version()
  59. File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp.py", line 107, in _send_version
  60. t, data = self._read_packet()
  61. File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp.py", line 174, in _read_packet
  62. x = self._read_all(4)
  63. File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp.py", line 161, in _read_all
  64. raise EOFError()
  65. EOFError
  66.  
  67. During handling of the above exception, another exception occurred:
  68.  
  69. Traceback (most recent call last):
  70. File "./test.py", line 13, in <module>
  71. ftp_client = ssh_client.client.open_sftp()
  72. File "/usr/local/lib/python3.6/dist-packages/paramiko/client.py", line 521, in open_sftp
  73. return self._transport.open_sftp_client()
  74. File "/usr/local/lib/python3.6/dist-packages/paramiko/transport.py", line 980, in open_sftp_client
  75. return SFTPClient.from_transport(self)
  76. File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 140, in from_transport
  77. return cls(chan)
  78. File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 105, in __init__
  79. raise SSHException('EOF during negotiation')
  80. paramiko.ssh_exception.SSHException: EOF during negotiation
Add Comment
Please, Sign In to add comment