Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3.6
- import paramiko
- import paramiko
- from paramiko import client
- class ssh:
- client = None
- def __init__(self, address, username, password):
- print("Connecting to server.")
- self.client = client.SSHClient()
- self.client.set_missing_host_key_policy(client.AutoAddPolicy())
- self.client.connect(address,
- username = username,
- password = password,
- look_for_keys=False)
- def sendCommand(self,
- command):
- if(self.client):
- stdin, stdout, stderr = self.client.exec_command(command)
- output = []
- while not stdout.channel.exit_status_ready():
- portion = stdout.readlines()
- # print(portion)
- if len(portion) > 0:
- output.append(portion)
- result = self.output_to_string(output)
- return result
- else:
- raise Exception("Connection not opened.")
- def output_to_string(self, output):
- result = ""
- for line in output:
- for el in line:
- # result += str(line, "utf8")
- result += el
- return result
- #!/usr/bin/python3.6
- import ssh_own
- import os
- home = os.environ["HOME"]
- ssh_client = ssh_own.ssh("ip", "username", "password")
- ftp_client = ssh_client.client.open_sftp()
- ftp_client.put("/home/localuser/README.md", "/home/username/README.md")
- ftp_client.close()
- Connecting to server.
- Traceback (most recent call last):
- File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 103, in __init__
- server_version = self._send_version()
- File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp.py", line 107, in _send_version
- t, data = self._read_packet()
- File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp.py", line 174, in _read_packet
- x = self._read_all(4)
- File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp.py", line 161, in _read_all
- raise EOFError()
- EOFError
- During handling of the above exception, another exception occurred:
- Traceback (most recent call last):
- File "./test.py", line 13, in <module>
- ftp_client = ssh_client.client.open_sftp()
- File "/usr/local/lib/python3.6/dist-packages/paramiko/client.py", line 521, in open_sftp
- return self._transport.open_sftp_client()
- File "/usr/local/lib/python3.6/dist-packages/paramiko/transport.py", line 980, in open_sftp_client
- return SFTPClient.from_transport(self)
- File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 140, in from_transport
- return cls(chan)
- File "/usr/local/lib/python3.6/dist-packages/paramiko/sftp_client.py", line 105, in __init__
- raise SSHException('EOF during negotiation')
- paramiko.ssh_exception.SSHException: EOF during negotiation
Add Comment
Please, Sign In to add comment