Sindbad~EG File Manager
3
.�]�I � @ sX d Z ddlmZmZmZmZ ddlZddlZddgZG dd� de�Z G dd� de�Z
dS )a4 This class extends pexpect.spawn to specialize setting up SSH connections.
This adds methods for login, logout, and expecting the shell prompt.
PEXPECT LICENSE
This license is approved by the OSI and FSF as GPL-compatible.
http://opensource.org/licenses/isc-license.txt
Copyright (c) 2012, Noah Spurrier <noah@noah.org>
PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
� )�ExceptionPexpect�TIMEOUT�EOF�spawnN�ExceptionPxssh�pxsshc @ s e Zd ZdZdS )r z!Raised for pxssh exceptions.
N)�__name__�
__module__�__qualname__�__doc__� r r �/usr/lib/python3.6/pxssh.pyr s c @ sn e Zd ZdZddddddddi ddfdd�Zd d
� Zdd� Zddd�Zddd�Zdd� Z d dd�Z
dd� ZdS )!r aH
This class extends pexpect.spawn to specialize setting up SSH
connections. This adds methods for login, logout, and expecting the shell
prompt. It does various tricky things to handle many situations in the SSH
login process. For example, if the session is your first login, then pxssh
automatically accepts the remote certificate; or if you have public key
authentication setup then pxssh won't wait for the password prompt.
pxssh uses the shell prompt to synchronize output from the remote host. In
order to make this more robust it sets the shell prompt to something more
unique than just $ or #. This should work on most Borne/Bash or Csh style
shells.
Example that runs a few commands on a remote server and prints the result::
from pexpect import pxssh
import getpass
try:
s = pxssh.pxssh()
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login(hostname, username, password)
s.sendline('uptime') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.sendline('ls -l')
s.prompt()
print(s.before)
s.sendline('df')
s.prompt()
print(s.before)
s.logout()
except pxssh.ExceptionPxssh as e:
print("pxssh failed on login.")
print(e)
Example showing how to specify SSH options::
from pexpect import pxssh
s = pxssh.pxssh(options={
"StrictHostKeyChecking": "no",
"UserKnownHostsFile": "/dev/null"})
...
Note that if you have ssh-agent running while doing development with pxssh
then this can lead to a lot of confusion. Many X display managers (xdm,
gdm, kdm, etc.) will automatically start a GUI agent. You may see a GUI
dialog box popup asking for a password during development. You should turn
off any key agents during testing. The 'force_password' attribute will turn
off public key authentication. This will only work if the remote SSH server
is configured to allow password logins. Example of using 'force_password'
attribute::
s = pxssh.pxssh()
s.force_password = True
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login (hostname, username, password)
� i� NT�strictc C sX t j| d |||||||||
|d� d| _d| _| j| _d| _d| _d | _d| _| | _ d S )
N)
�timeout�maxread�searchwindowsize�logfile�cwd�env�
ignore_sighup�echo�encoding�codec_errorsz<pxssh>z\[PEXPECT\][\$\#] zPS1='[PEXPECT]\$ 'zset prompt='[PEXPECT]\$ 'z-o'RSAAuthentication=no'z -o 'PubkeyAuthentication=no'Fz5-o'RSAAuthentication=no' -o 'PubkeyAuthentication=no')
r �__init__�nameZ
UNIQUE_PROMPT�PROMPT�
PROMPT_SET_SH�PROMPT_SET_CSH�SSH_OPTS�force_password�options)�selfr r r r r r r r r! r r r r r
r ` s
zpxssh.__init__c C s� t |�t |� }}||kr.|| }}|| }}t|d �}x�td|d �D ]�}||gdg| }}xptd|d �D ]^}|| d ||d d } }
||d }||d ||d kr�|d }t| |
|�||<