File manager - Edit - /usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/__pycache__/client.cpython-310.pyc
Back
o �h�� � @ s& d Z ddlmZ ddlZddlZddlZddlZddlZddlm Z m Z ddlmZ ddl mZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZmZmZ ddlm Z ddl!m"Z" G dd� de"�Z#G dd� d�Z$G dd� de$�Z%G dd� de$�Z&G dd� de$�Z'dS )z SSH client & key policies � )�hexlifyN)�ECONNREFUSED�EHOSTUNREACH)�Agent)�DEBUG)�SSH_PORT)�DSSKey)�ECDSAKey)� Ed25519Key)�HostKeys)�RSAKey)�SSHException�BadHostKeyException�NoValidConnectionsError)� Transport)�ClosingContextManagerc @ s� e Zd ZdZdd� Zd,dd�Zdd� Zd d � Zdd� Zd d� Z dd� Z dd� Zedddddddddddddddddddddfdd�Z dd� Z d-dd�Z d.d d!�Zd"d#� Zd$d%� Zd&d'� Zd(d)� Zd*d+� ZdS )/� SSHClienta� A high-level representation of a session with an SSH server. This class wraps `.Transport`, `.Channel`, and `.SFTPClient` to take care of most aspects of authenticating and opening channels. A typical use case is:: client = SSHClient() client.load_system_host_keys() client.connect('ssh.example.com') stdin, stdout, stderr = client.exec_command('ls -l') You may pass in explicit overrides for authentication and server host key checking. The default mechanism is to try to use local key files or an SSH agent (if one is running). Instances of this class may be used as context managers. .. versionadded:: 1.6 c C s4 t � | _t � | _d| _d| _t� | _d| _d| _dS )z) Create a new SSHClient. N) r �_system_host_keys� _host_keys�_host_keys_filename�_log_channel�RejectPolicy�_policy� _transport�_agent��self� r �E/usr/local/CyberPanel/lib/python3.10/site-packages/paramiko/client.py�__init__D s zSSHClient.__init__Nc C sL |du rt j�d�}z | j�|� W dS ty Y dS w | j�|� dS )a� Load host keys from a system (read-only) file. Host keys read with this method will not be saved back by `save_host_keys`. This method can be called multiple times. Each new set of host keys will be merged with the existing set (new replacing old if there are conflicts). If ``filename`` is left as ``None``, an attempt will be made to read keys from the user's local "known hosts" file, as used by OpenSSH, and no exception will be raised if the file can't be read. This is probably only useful on posix. :param str filename: the filename to read, or ``None`` :raises: ``IOError`` -- if a filename was provided and the file could not be read Nz~/.ssh/known_hosts)�os�path� expanduserr �load�IOError�r �filenamer r r �load_system_host_keysP s ��zSSHClient.load_system_host_keysc C s || _ | j�|� dS )a� Load host keys from a local host-key file. Host keys read with this method will be checked after keys loaded via `load_system_host_keys`, but will be saved back by `save_host_keys` (so they can be modified). The missing host key policy `.AutoAddPolicy` adds keys to this set and saves them, when connecting to a previously-unknown server. This method can be called multiple times. Each new set of host keys will be merged with the existing set (new replacing old if there are conflicts). When automatically saving, the last hostname is used. :param str filename: the filename to read :raises: ``IOError`` -- if the filename could not be read N)r r r# r% r r r �load_host_keysm s zSSHClient.load_host_keysc C s� | j dur| �| j � t|d��(}| j�� D ]\}}|�� D ]\}}|�d�|||�� �� qqW d � dS 1 s;w Y dS )aO Save the host keys back to a file. Only the host keys loaded with `load_host_keys` (plus any added directly) will be saved -- not any host keys loaded with `load_system_host_keys`. :param str filename: the filename to save to :raises: ``IOError`` -- if the file could not be written N�wz {} {} {} )r r( �openr �items�write�format� get_base64)r r&