diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-02-13 21:39:41 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-02-13 21:39:41 +0100 |
commit | f1ef9c053c84515761f59412a91ca3adbc8e7392 (patch) | |
tree | 9adfb42a73cf1aa61556d16ee5665e6c3f611dd4 /_ssh_client.py | |
parent | b476a22f4a85d90ccaec2ee27a528d5bfe428a82 (diff) |
Move the python files to a package.
Diffstat (limited to '_ssh_client.py')
-rw-r--r-- | _ssh_client.py | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/_ssh_client.py b/_ssh_client.py deleted file mode 100644 index f1c9e23..0000000 --- a/_ssh_client.py +++ /dev/null @@ -1,45 +0,0 @@ -import paramiko.client as pmc - -from ._sshfp_policy import SSHFPPolicy - -class SSHConnection: - """ - An SSH client connection to a remote server, with support for a proxy "jump" - host, like OpenSSH's 'ssh -J'. Uses only SSHFP for host key verification. - - May be used as a context manager. - - :param SSHRemote remote: Remote host to connect to. - """ - _proxy_conn = None - _client = None - - def __init__(self, remote): - sock = None - if remote.proxy_remote is not None: - self._proxy_conn = SSHConnection(remote.proxy_remote) - t = self._proxy_conn.get_transport() - sock = t.open_channel('direct-tcpip', (remote.host, remote.port), ('localhost', 0)) - - self._client = pmc.SSHClient() - self._client.set_missing_host_key_policy(SSHFPPolicy()) - self._client.connect(remote.host, remote.port, remote.username, - sock = sock) - - def close(self): - if self._client: - self._client.close() - self._client = None - if self._proxy_conn: - self._proxy_conn.close() - self._proxy_conn = None - - def exec_command(self, *args, **kwargs): - return self._client.exec_command(*args, **kwargs) - def get_transport(self): - return self._client.get_transport() - - def __enter__(self): - return self - def __exit__(self, exc_type, exc_value, traceback): - self.close() |