Ñò
*ª¬Lc           @   se   d  Z  d d k Z d d k Z d d k Z d e f d „  ƒ  YZ d „  Z e d j o e ƒ  n d S(   s   Friendly Python SSH2 interface.iÿÿÿÿNt
   Connectionc           B   s_   e  Z d  Z d	 d	 d	 d d „ Z d „  Z d	 d „ Z d	 d „ Z d „  Z d „  Z	 d „  Z
 RS(
   sr   Connects and logs into the specified hostname. 
    Arguments that are not given are guessed from the environment.i   c   	      C   s<  t  |  _ d  |  _ | p t i d } n t i d d ƒ d } t i	 i
 | ƒ t i | | f ƒ |  _ t |  _ | o |  i i d | d | ƒ n¤ | p_ t i i t i i d ƒ ƒ o
 d } qû t i i t i i d ƒ ƒ o
 d } qû t d	 ‚ n t i i | ƒ } t i i | ƒ } |  i i d | d
 | ƒ d  S(   Nt   LOGNAMEs   .txts   ssh-i   t   usernamet   passwords   ~/.ssh/id_rsas   ~/.ssh/id_dsas)   You have not specified a password or key.t   pkey(   t   Falset
   _sftp_livet   Nonet   _sftpt   ost   environt   tempfilet   mkstempt   paramikot   utilt   log_to_filet	   Transportt
   _transportt   Truet   _tranport_livet   connectt   patht   existst
   expandusert	   TypeErrort   RSAKeyt   from_private_key_file(	   t   selft   hostR   t   private_keyR   t   portt   templogt   private_key_filet   rsa_key(    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyt   __init__   s&    			

c         C   s3   |  i  p% t i i |  i ƒ |  _ t |  _  n d S(   s   Establish the SFTP connection.N(   R   R   t
   SFTPClientt   from_transportR   R   R   (   R   (    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyt   _sftp_connect1   s    
c         C   sB   | p t  i i | ƒ d } n |  i ƒ  |  i i | | ƒ d S(   s9   Copies a file between the remote host and the local host.i   N(   R	   R   t   splitR%   R   t   get(   R   t
   remotepatht	   localpath(    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyR'   7   s    
c         C   sB   | p t  i i | ƒ d } n |  i ƒ  |  i i | | ƒ d S(   s9   Copies a file between the local host and the remote host.i   N(   R	   R   R&   R%   R   t   put(   R   R)   R(   (    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyR*   >   s    
c         C   sZ   |  i  i ƒ  } | i | ƒ | i d d ƒ i ƒ  } | o | S| i d d ƒ i ƒ  Sd S(   s/   Execute the given commands on a remote machine.t   rbiÿÿÿÿN(   R   t   open_sessiont   exec_commandt   makefilet	   readlinest   makefile_stderr(   R   t   commandt   channelt   output(    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyt   executeE   s    c         C   sL   |  i  o |  i i ƒ  t |  _  n |  i o |  i i ƒ  t |  _ n d S(   s$   Closes the connection and cleans up.N(   R   R   t   closeR   R   R   (   R   (    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyR5   O   s    

c         C   s   |  i  ƒ  d S(   s-   Attempt to clean up if not explicitly closed.N(   R5   (   R   (    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyt   __del__Z   s    N(   t   __name__t
   __module__t   __doc__R   R"   R%   R'   R*   R4   R5   R6   (    (    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyR       s   !		
	c          C   s'   t  d ƒ }  |  i d ƒ |  i ƒ  d S(   s!   Little test when called directly.s   example.coms   ssh.pyN(   R    R*   R5   (   t   myssh(    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyt   main^   s    t   __main__(   R9   R	   R   R   t   objectR    R;   R7   (    (    (    sB   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\ssh.pyt   <module>   s   W	