+
    Dfj                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIHtHtHtHt ^ RIHtHtHt ^ RIHtHtHtHt ^ RIHtHtHtHt ^ RIHt ^ RI H!t!H"t"H#t# ^ RI$H%t%  ! R	 R
]PL                  4      t'R t(R t)R t*R t+R t, ! R R4      t- ! R R]P\                  4      t/]0! ]/R]/Pb                  4        ! R R]Pd                  4      t2 ! R R]Pf                  4      t4]5R8X  d
   ](! 4        R# R# )z0
Implementation module for the I{cftp} command.
N)ListOptionalTextIOUnion)connectdefaultoptions)channelcommon
connectionfiletransfer)deferreactorstdioutils)basic)failurelogusage)FilePathc                      a  ] tR t^t o RtRt. RO. RO. RO. RO.t]P                  ! RR/]P                  ! 4       ]P                  ! RR7      .R7      tRR	 ltV 3R
 ltRtV tR# )ClientOptionszUsage:   cftp [options] [user@]host
         cftp [options] [user@]host[:dir[/]]
         cftp [options] [user@]host[:file [localfile]]
zncftp is a client for logging into a remote machine and executing commands to send and receive file information
buffersizeNz,Size of send/receive buffer (default: 32768)z
local file)descr)descriptionsextraActionsc                    R V R&   RV9   d0   VP                  R^4      w  qR&   V R,          P                  R4       WR&   W R&   R# ) 
remotePath:/host	localPathN)splitrstrip)selfr!   r"   s   &&&</usr/lib/python3/dist-packages/twisted/conch/scripts/cftp.py	parseArgsClientOptions.parseArgs5   sM    \$;'+zz#q'9$D|$%%c*V%[    c                l   < V ^8  d   Qh/ S[ S[ S[S[S[S[3,          ,          ,          ,          ;R&   # )   optParameters)r   r   r   strint)format__classdict__s   "r&   __annotate__ClientOptions.__annotate__   s+      XeCHo678  r)    )r   Bi   z0Size of the buffer to use for sending/receiving.)	batchfilebNz-File to read commands from, or '-' for stdin.)requestsR   z6Number of requests to make before waiting for a reply.)	subsystemssftpz'Subsystem/server program to connect to.N)__name__
__module____qualname____firstlineno__synopsislongdescr,   r   CompletionsCompleteUserAtHostCompleteFilescompDatar'   __annotate_func____static_attributes____classdictcell__r0   s   @r&   r   r      ss     H
	B  	WQVM	<M   "$RS$$&l3
H&3  r)   r   c                     \         P                  R ,          p RV 9   d6   V P                  R4      pWV^,            V ,           p W^,           V^,           1 \        4       p VP                  ! V 4       VR,          '       dA   \         P                  p\        P                  ! \         P                  4       V\         n	        M\        P                  ! 4        \        V4       \        P                   ! 4        R#   \
        P                   d3   p\        RT,          4       \         P                  ! ^4        Rp?LRp?ii ; i)   NNz-lz	ERROR: %sNr   )sysargvindexr   parseOptionsr   
UsageErrorprintexitstdoutr   startLoggingstderrdiscardLogs	doConnectr   run)argsir   urealouts        r&   r[   r[   >   s    88B<Dt|JJtA%QQoGT" u~~**$
gKKM  kAos   C7 7D>(D99D>c                      ^s  \        P                  ! 4        \        P
                  ! \        P                  ! 4       4       h   \         d     L7i ; i)r+   )
exitStatusr   stopBaseExceptionr   errr   Failurer3   r)   r&   handleErrorrf   T   sA    J GGGOO	  s   A AAc                    R V R,          9   d#   V R,          P                  R ^4      w  V R&   V R&   V R,          pV R,          '       g   \        P                  ! 4       V R&   V R,          '       g   ^V R&   M\        V R,          4      V R&   V R,          pV R,          p\	        4       pWn        \        P                  p\        P                  ! V R,          W4      p\        P                  ! WWV4      P                  \        4       R# )@r!   userportN)r#   getpassgetuserr.   SSHConnectionr   r   verifyHostKeySSHUserAuthClientr   
addErrback_ebExit)r   r!   rj   connvhkuaos   &     r&   rZ   rZ   _   s    
gfo+26?+@+@a+H(6?D6??!//+6??gfo.6?D6?D?DL


C

#
#GFOW
CCOODc2==gFr)   c                     \        V P                  R 4      '       d   V P                  P                  pM\        V 4      p\        V4        \        P
                  ! 4        R#   \         d     R# i ; i)valueN)hasattrrv   r-   rT   r   rb   rc   )fr;   s   & r&   rq   rq   r   sP    qww  GGMMF	!H s   A" "A10A1c                      R # r=   r3   )r\   s   *r&   _ignorerz   ~   s    r)   c                   ,   a  ] tR t^t o R tR tRtV tR# )FileWrapperc                n    Wn         R V n        VP                  ^ ^4       VP                  4       V n        R# )        N)rx   totalseektellsizer%   rx   s   &&r&   __init__FileWrapper.__init__   s(    
	q!FFH	r)   c                .    \        V P                  V4      # r=   )getattrrx   )r%   attrs   &&r&   __getattr__FileWrapper.__getattr__   s    tvvt$$r)   )rx   r   r   N)r>   r?   r@   rA   r   r   rI   rJ   rK   s   @r&   r|   r|      s     % %r)   r|   c                     a  ] tR t^t o ]tRtRt]tR@R lt	R t
R tR tR tR	 tR
 tR tR tR tR tR tR tR tR tR tRAR ltR tR tR tR tR tR tR t R t!R t"R t#R t$R  t%RBR! lt&R" t'R# t(R$ t)R% t*R& t+R' t,R( t-R) t.R* t/R+ t0R, t1R- t2R. t3R/ t4R0 t5]5t6R1 t7R2 t8R3 t9R4 t:R5 t;R6 t<R7 t=R8 t>R9 t?R: t@R; tAR< tBR= tCR> tDR?tEV tFR# )CStdioClientzcftp>    
Nc                l    Wn         R V n        W n        V'       * ;'       d    ^;'       g    ^ V n        R# r   N)clientcurrentDirectoryfileuseProgressBar)r%   r   rx   s   &&&r&   r   StdioClient.__init__   s,     "	#$u{{00qr)   c                n    V P                   P                  R 4      P                  V P                  4       R# r   )r   realPathaddCallback_cbSetCurDirr%   s   &r&   connectionMadeStdioClient.connectionMade   s%    R ,,T->->?r)   c                2    Wn         V P                  4        R # r=   )r   _newLiner%   paths   &&r&   r   StdioClient._cbSetCurDir   s     $r)   c                    \        V\        4      '       d   VP                  R 4      pV P                  P	                  V4      # utf-8)
isinstancer-   encode	transportwrite)r%   msgs   &&r&   _writeToTransportStdioClient._writeToTransport   s2    c3**W%C~~##C((r)   c                N   V P                   P                  P                  '       d   R # \        V\        4      '       d   VP                  R4      p\        P                  ! RV,          4       VP                  4       pV'       g   V P                  4        R # V P                  '       d)   VP                  R4      '       d   ^V n        VR,          pM^ V n        V P                  V4      pVe9   VP                  V P                  4       VP!                  V P"                  4       R # R # )Nr   zgot line %s-rM   )r   r   localClosedr   bytesdecoder   r   lstripr   r   
startswithignoreErrors_dispatchCommandr   
_cbCommandrp   
_ebCommand)r%   lineds   && r&   lineReceivedStdioClient.lineReceived   s    ;;  ,,,dE"";;w'D$%{{}MMO999-- !D8D !D!!$'=MM$//*LL) r)   c                :   R V9   d&   VP                  R ^4      w  r#VP                  4       pMTRr2VP                  R4      '       d3   V P                  pVR,          R ,           V,           P	                  4       pMAVP                  4       p\        P                  ! RV,          4       \        V RV,          R4      pVe   \        P                  ! WC4      # RV,          pV P                  \        P                  ! \        V4      4      4       V P                  4        R# ) r   !rM   zlooking up cmd %szcmd_%sNzNo command called `%s')r#   r   r   cmd_EXECstripupperr   r   r   r   maybeDeferredr   r   re   NotImplementedErrorr   )r%   r   commandrestrx   errMsgs   &&    r&   r   StdioClient._dispatchCommand   s    $; JJsA.MG;;=D "Tc""ABK#%,335DmmoGGG''12h0$7A=&&q//-9FOOGOO,?,GHIMMOr)   c                L   \         P                  ! V4       VP                  \        \        P
                  \        \        4      pV\        8X  d#   V P                  V P                  R 4      4       R# V\        P
                  8X  dG   RVP                  P                  VP                  P                  3,          pV P                  V4       R# V\        \        39   dG   RVP                  P                  VP                  P                  3,          pV P                  V4       R# R# )r   zremote error %i: %s
zlocal error %i: %s
N)r   r   trapr   r   	SFTPErrorOSErrorIOErrorr   cmd_HELPrv   codemessageerrnostrerror)r%   rx   er   s   &&  r&   _printFailureStdioClient._printFailure   s    
FF&(>(>Q##""4==#45,(((,aggoo/NNF""6*7G$$+qww}}agg>N>N.OOF""6* %r)   c                   V P                   P                  P                  '       d   R # V P                  V P                  4       ^ V n        V P                  '       d{   V P                  P                  4       pV'       g'   V P                   P                  P                  4        R # V P                  V4       V P                  VP                  4       4       R # R # r=   )r   r   r   r   psr   r   readlineloseConnectionr   r   )r%   ls   & r&   r   StdioClient._newLine   s    ;;  ,,,tww'999		""$A%%446&&q)!!!''), r)   c                    Vea   \        V\        4      '       d   VP                  R4      pV P                  V4       VP	                  R4      '       g   V P                  R4       V P                  4        R # )Nr   r   )r   r-   r   r   endswithr   )r%   results   &&r&   r   StdioClient._cbCommand   sW    &#&&w/""6*??5))&&u-r)   c                    V P                  V4       V P                  '       d7   V P                  '       g%   V P                  P                  P                  4        V P                  4        R # r=   )r   r   r   r   r   r   r   r   s   &&r&   r   StdioClient._ebCommand   sC    1999T...KK!!002r)   c                   V P                  V4      w  rVP                  R 4      '       g
   VR ,          pT;'       d3    \        P                  P	                  V P
                  V4      ;'       g    RpV P                  P                  V4      pVP                  V P                  4       VP                  V P                  4       V# )r    r   )_getFilenamer   osr   joinr   r   openDirectoryr   _cbCdrp   r   )r%   r   r   newPathr   s   &&   r&   cmd_CDStdioClient.cmd_CD   s    &&t,
}}S!!CKDDD277<<(=(=tDJJKK%%g.	djj!	T__%r)   c                    VP                  4        V P                  P                  VP                  4      pVP	                  V P
                  4       V# r=   )closer   r   namer   	_cbCurDir)r%   	directoryr   s   && r&   r   StdioClient._cbCd  s9    KK  0	dnn%r)   c                    Wn         R # r=   r   r   s   &&r&   r   StdioClient._cbCurDir  s     $r)   c                    VP                  R ^4      w  r!V P                  V4      w  r1\        V4      pV P                  P	                  V4      pVP                  V P                  W2R7       V# )N)grpr#   r   r.   r   getAttrsr   _cbSetUsrGrp)r%   r   r   r   r   s   &&   r&   	cmd_CHGRPStdioClient.cmd_CHGRP
  ^    JJtQ'	&&t,
#hKK  &	d''7r)   c                    VP                  R ^4      w  r!V P                  V4      w  r1\        V^4      pV P                  P	                  VRV/4      pVP                  \        4       V# )Npermissions)r#   r   r.   r   setAttrsr   rz   )r%   r   modr   r   s   &&   r&   	cmd_CHMODStdioClient.cmd_CHMOD  s]    JJtQ'	&&t,
#qkKK  s';<	gr)   c                    VP                  R ^4      w  r!V P                  V4      w  r1\        V4      pV P                  P	                  V4      pVP                  V P                  W2R7       V# )N)usrr   )r%   r   r   r   r   s   &&   r&   	cmd_CHOWNStdioClient.cmd_CHOWN  r   r)   c                    / pVR J;'       d    T;'       g
    VR,          VR&   VR J;'       d    T;'       g
    VR,          VR&   V P                   P                  W%4      pVP                  \        4       V# )Nuidgid)r   r   r   rz   )r%   attrsr   r   r   newr   s   &&&&&  r&   r   StdioClient._cbSetUsrGrp"  sn    o..3>>%,E
o..3>>%,E
KK  +	gr)   c                   V P                  V4      w  r!R V9   g   RV9   du   V'       d<   V P                  V4      w  r1\        P                  P                  V4      '       g   R# MRpV P	                  V4      pVP                  V P                  V4       V# V'       d   V P                  V4      w  r1M&\        P                  P                  V4      ^,          p\        P                  ! W#34       \        VR^ 4      p\        V P                  4      P                  V4      pV P                  P                  VP                  \         P"                  / 4      pVP                  V P$                  V4       VP'                  V P(                  V4       V# )*?z'Wildcard get with non-directory target.r)   wb)r   r   r   isdir_remoteGlobr   _cbGetMultipler#   r   r   openr   r   childr   openFiler   FXF_READ_cbGetOpenFilerp   
_ebCloseLf)r%   r   remotelocalr   lfr   s   &&     r&   cmd_GETStdioClient.cmd_GET*  s3   ((.&=C6M"//5ww}}U++D ,   (AMM$--u5H++D1KE4GGMM&)!,E %q!--.44V<KK  L,A,A2F	d))2.	T__b)r)   c                &    V P                  R W4      # r=   )_cbGetMultipleNext)r%   filesr  s   &&&r&   r  StdioClient._cbGetMultipleB  s    &&tU::r)   c                (   \        V\        P                  4      '       d   V P                  V4       MAV'       d:   V P	                  V4       VP                  R 4      '       g   V P	                  R 4       V'       g   R# VP                  ^ 4      ^ ,          p\        \        P                  P                  V\        P                  P                  V4      ^,          4      R^ 4      p\        V P                  4      P                  V4      pV P                  P!                  VP                  \"        P$                  / 4      pVP'                  V P(                  V4       VP+                  V P,                  V4       VP/                  V P0                  W#4       V# )
Nr  )r   r   re   r   r   r   popr  r   r   r   r#   r   r   r  r   r  r   r  r   r  rp   r  addBothr  )r%   resr  r  rx   r  r   r   s   &&&&    r&   r  StdioClient._cbGetMultipleNextF  s   c7??++s#""3'<<%%&&t,IIaLO"'',,ubggmmA&6q&9:D!D--.44Q7KK  L,A,A2F	d))2.	T__b)			$))58r)   c                &    VP                  4        V# r=   )r   )r%   rx   r  s   &&&r&   r  StdioClient._ebCloseLfX  s    

r)   c                V    VP                  4       P                  V P                  W4      # r=   )r   r   _cbGetFileSize)r%   rfr  s   &&&r&   r  StdioClient._cbGetOpenFile\  s!    {{}(()<)<bEEr)   c           
        \         P                  ! VR ,          4      '       g4   VP                  4        VP                  4        RVP                  ,          # VR,          Vn        V P
                  P                  P                  P                  R,          pV P
                  P                  P                  P                  R,          pRVn	        . p. pV P                  P                  4       p\        V4       F)  p	V P                  RW#V^ WH4      p
VP                  V
4       K+  	  \        P                   ! V^R7      pVP#                  V P$                  W#4       V# )r   zCan't get non-regular file: %sr   r   r7   r~   r   fireOnOneErrback)statS_ISREGr   r   r   r   r   rr   r   r   r   secondsrange
_cbGetReadappendr   DeferredListr   
_cbGetDone)r%   r  r)  r  
bufferSizenumRequestsdListchunks	startTimer]   r   dls   &&&&        r&   r(  StdioClient._cbGetFileSize_  s    ||E-011HHJHHJ3bgg==-[[**//77E
kk++0088DLL((*	{#ABFAzMALLO $ :
t/	r)   c                   ^ pV Fa  pVR8X  d    R# W#^ ,          8w  d?   VP                  V4      pVP                  WBV^ ,          34       W#^ ,          V,
          3u # V^,          pKc  	  \        V P                  P                  P
                  P                  R,          4      pVP                  W"V,           34       W%3# )    eofNr   )rQ   insertr.   r   r   rr   r   r3  )r%   r9  endchunkr]   bufSizes   &&    r&   _getNextChunkStdioClient._getNextChunkr  s    Ee|AhLL'auQx11X^,,(C  dkk++0088FGs'M*+~r)   c           	        V'       d   \        V\        P                  4      '       dd   \        P                  ! R V,          4       TpVP                  \        4       VP                  WUV,           34      p	WI VP                  WR34       MV'       d   \        P                  ! R\        V4      ,          4       VP                  V4       VP                  V4       \        V4      V8w  dg   \        P                  ! R\        V4      V3,          4       VP                  WUV,           34      p	WI VP                  WV\        V4      ,           34       V;P                  \        V4      ,          un        V P                  '       d   V P                  W'4       V P                  V4      p
V
'       g   R# V
w  r[\        P                  ! RWUV,           3,          4       VP!                  W[4      pVP#                  V P$                  W#WEW4       V# )zget read err: %sr?  zget read data: %iz#got less than we asked for: %i < %iNzasking for %i -> %i)r   r   re   r   r   r   EOFErrorrQ   r@  lenr   r   r   r   _printProgressBarrD  	readChunkr"  r2  )r%   datar)  r  r9  startr   r:  reasonr]   rB  lengthr   s   &&&&&&&&     r&   r2  StdioClient._cbGetRead  sw   JtW__55GG&-.FKK!eT\23A	MM!U^,GG'#d)34GGENHHTN4yD =TD@QQRLL%!67IaT):!;<HHD	!H""21""6*!ME%(??@LL'			$//26&Lr)   c                    \         P                  ! R 4       VP                  4        VP                  4        V P                  '       d   V P	                  R4       RVP
                   RVP
                   2# )zget doner   Transferred  to )r   r   r   r   r   r   r%   ignoredr)  r  s   &&&&r&   r5  StdioClient._cbGetDone  sU    




""4(bggYd277)44r)   c                   V P                  V4      w  r!RV9   g   RV9   dp   V'       d?   V P                  V4      w  r1\        P                  P                  V P                  V4      pMRp\
        P
                  ! V4      pV P                  WC4      # V'       d   V P                  V4      w  r1M&\        P                  P                  V4      ^,          pV P                  W#4      # )z
Do an upload request for a single local file or a globing expression.

@param rest: Requested command line for the PUT command.
@type rest: L{str}

@return: A deferred which fires with L{None} when transfer is done.
@rtype: L{defer.Deferred}
r
  r  r   )	r   r   r   r   r   glob_putMultipleFilesr#   _putSingleFile)r%   r   r  r  r  s   &&   r&   cmd_PUTStdioClient.cmd_PUT  s     ''- %<3%<#006d&;&;VDIIe$E))%88 #006u-a0&&u55r)   c                .    V P                  RV.VRR7      # )a  
Perform an upload for a single file.

@param local: Path to local file.
@type local: L{str}.

@param remote: Remote path for the request relative to current working
    directory.
@type remote: L{str}

@return: A deferred which fires when transfer is done.
NT)single_cbPutMultipleNext)r%   r  r  s   &&&r&   rY  StdioClient._putSingleFile  s      &&teWfT&JJr)   c                &    V P                  RW4      # )a  
Perform an upload for a list of local files.

@param files: List of local files.
@type files: C{list} of L{str}.

@param remote: Remote path for the request relative to current working
    directory.
@type remote: L{str}

@return: A deferred which fires when transfer is done.
Nr^  )r%   r  r  s   &&&r&   rX  StdioClient._putMultipleFiles  s     &&tU;;r)   c                P   \        V\        P                  4      '       d   V P                  V4       MhV'       da   \        V\        4      '       d   VP                  R4      pV P                  V4       VP                  R4      '       g   V P                  R4       RpV'       d)   V'       g!    VP                  ^ 4      p\        VR4      pK0  V'       g   R# V'       d   TpM]\        P                  P                  V4      ^,          p\        P                  P                  W84      p\        P                   ! WV34       V P#                  XV4      p	V	P%                  V P&                  W#4       V	#   \         d,    T P                  \        P                  ! 4       4       Rp EK  i ; i)a   
Perform an upload for the next file in the list of local files.

@param previousResult: Result form previous file form the list.
@type previousResult: L{str}

@param files: List of local files.
@type files: C{list} of L{str}

@param remotePath: Remote path for the request relative to current
    working directory.
@type remotePath: L{str}

@param single: A flag which signals if this is a transfer for a single
    file in which case we use the exact remote path
@type single: L{bool}

@return: A deferred which fires when transfer is done.
r   r   Nrb)r   r   re   r   r-   r   r   r   r!  r  rc   r   r   r#   r   r   r   _putRemoteFiler"  r_  )
r%   previousResultr  r   r]  currentFilelocalStreamr  r   r   s
   &&&&&     r&   r_  StdioClient._cbPutMultipleNext  s8   ( ngoo66~..#..!/!6!6w!?"">2!**511&&u-K##iil";5 F77==-a0DWW\\*3FGGT:./V4			$))5=# ! #""7??#45"#s   .E/ /1F%$F%c                v   \         P                  P                  V P                  V4      p\        P
                  \        P                  ,          \        P                  ,          pV P                  P                  W4/ 4      pVP                  V P                  V4       VP                  V P                  V4       V# )a  
Do an upload request.

@param localStream: Local stream from where data is read.
@type localStream: File like object.

@param remotePath: Remote path for the request relative to current working directory.
@type remotePath: L{str}

@return: A deferred which fires when transfer is done.
)r   r   r   r   r   	FXF_WRITE	FXF_CREAT	FXF_TRUNCr   r  r   _cbPutOpenFilerp   r  )r%   rh  r   r  flagsr   s   &&&   r&   re  StdioClient._putRemoteFile  s     d33Z@&&)?)??,BXBXXKK  3	d));7	T__k2r)   c                   V P                   P                  P                  P                  R ,          pV P                  '       d   \        V4      p. p. pV P                  P                  4       p\        V4       F1  pV P                  RWWV4      pV'       g   K   VP                  V4       K3  	  \        P                  ! V^R7      p	V	P                  V P                  W4       V	# )r7   Nr,  )r   r   rr   r   r   r|   r   r0  r1  _cbPutWriter3  r   r4  r   
_cbPutDone)
r%   r)  r  r7  r8  r9  r:  r]   r   r;  s
   &&&       r&   rn  StdioClient._cbPutOpenFile+  s    kk++0088DRBLL((*	{#A  rvAAqQ $ :
t/	r)   c                n   V P                  V4      pVw  rxVP                  V4       VP                  V4      p	V P                  '       d4   V;P                  \        V	4      ,          un        V P                  W54       V	'       d1   VP                  Wy4      p
V
P                  V P                  W#WE4       V
# R # r=   )
rD  r   readr   r   rH  rI  
writeChunkr   rr  )r%   rT  r)  r  r9  r:  rB  rL  r   rK  r   s   &&&&&&     r&   rr  StdioClient._cbPutWrite:  s    ""6*
wwt}HHD	!H""21e*AMM$**BFFHr)   c                    VP                  4        VP                  4        V P                  '       d   V P                  R 4       RVP                   RVP                   2# )r   rQ  rR  )r   r   r   r   rS  s   &&&&r&   rs  StdioClient._cbPutDoneI  sI    



""4(bggYd277)44r)   c                2    \         P                  ! V4       R # r=   )r   chdirr   s   &&r&   cmd_LCDStdioClient.cmd_LCDP  s    
r)   c                   a  S P                  V4      w  r!S P                  V4      w  r1\        V 3R  lW#34      w  r#S P                  P                  W#4      P	                  \
        4      # )c                 X   < \         P                  P                  SP                  V 4      # r=   r   r   r   r   xr%   s   &r&   <lambda>$StdioClient.cmd_LN.<locals>.<lambda>W      bggll4#8#8!<r)   )r   mapr   makeLinkr   rz   )r%   r   linkpath
targetpaths   f&  r&   cmd_LNStdioClient.cmd_LNS  s_    **40,,T2
"<x>T 
 {{##H9EEgNNr)   c                b   . pVP                  4       pV'       d~   V^ ,          '       do   V^ ,          ^ ,          R8X  dZ   VP                  ^ 4      R,          pV F9  pVR8X  d   VP                  ! R4       K  VR8X  g   K'  VP                  ! R4       K;  	  K  RP                  V4      pV P	                  V4      w  rQV'       g   V P
                  R,           pM*\        P                  P                  V P
                  V4      pV P                  V4      pVP                  V P                  V4       V# )	r>  r   rM   r   verboseaallr   r    )r#   r!  r3  r   r   r   r   r   r  r   _cbDisplayFiles)r%   r   r   optsor   fullPathr   s   &&      r&   cmd_LSStdioClient.cmd_LS[  s     zz|tAww471:#488A;r?D8NN9-#XNN5)	 
 xx~&&t,
,,s2Hww||D$9$94@HX&	d**G4r)   c                P   VP                  4        R V9  d1   V Uu. uF$  q3^ ,          P                  R4      '       d   K"  VNK&  	  ppRV9   d   V Uu. uF  q3^,          NK  	  ppMV Uu. uF  q3^ ,          NK  	  ppV'       g   R# RP                  V4      # u upi u upi u upi )r     .r  Nr   )sortr   r   )r%   r  r   rx   liness   &&&  r&   r  StdioClient._cbDisplayFilest  s    

 %C1qT__T-BQQEC#()5aqTT5E)E#()5aqTT5E)::e$$ D))s   B BB+B#c                    V P                  V4      w  r\        P                  P                  V P                  V4      pV P
                  P                  V/ 4      P                  \        4      # r=   )	r   r   r   r   r   r   makeDirectoryr   rz   r%   r   r   s   && r&   	cmd_MKDIRStdioClient.cmd_MKDIR  sP    &&t,
ww||D1148{{((r2>>wGGr)   c                    V P                  V4      w  r\        P                  P                  V P                  V4      pV P
                  P                  V4      P                  \        4      # r=   )	r   r   r   r   r   r   removeDirectoryr   rz   r  s   && r&   	cmd_RMDIRStdioClient.cmd_RMDIR  sN    &&t,
ww||D1148{{**40<<WEEr)   c                @    \         P                  ! R V,          4       R# )zmkdir %sNr   systemr   s   &&r&   
cmd_LMKDIRStdioClient.cmd_LMKDIR  s    
		*t#$r)   c                    V P                  V4      w  r\        P                  P                  V P                  V4      pV P
                  P                  V4      P                  \        4      # r=   )	r   r   r   r   r   r   
removeFiler   rz   r  s   && r&   cmd_RMStdioClient.cmd_RM  sN    &&t,
ww||D1148{{%%d+77@@r)   c                @    \         P                  ! R V,          4       R# )zls %sNr  )r%   r   s   &&r&   cmd_LLSStdioClient.cmd_LLS  s    
		'D.!r)   c                   a  S P                  V4      w  r!S P                  V4      w  r1\        V 3R  lW#34      w  r#S P                  P                  W#4      P	                  \
        4      # )c                 X   < \         P                  P                  SP                  V 4      # r=   r  r  s   &r&   r  (StdioClient.cmd_RENAME.<locals>.<lambda>  r  r)   )r   r  r   
renameFiler   rz   )r%   r   oldpathnewpaths   f&  r&   
cmd_RENAMEStdioClient.cmd_RENAME  s^    ))$/))$/<w>P
 {{%%g7CCGLLr)   c                N    V P                   P                  P                  4        R # r=   )r   r   r   r%   rT  s   &&r&   cmd_EXITStdioClient.cmd_EXIT  s    ,,.r)   c                    R V P                   P                  ,          p\        V\        4      '       d   VP	                  R4      pV# )zSFTP version %ir   )r   versionr   r-   r   )r%   rT  r  s   && r&   cmd_VERSIONStdioClient.cmd_VERSION  s6    #dkk&9&99gs##nnW-Gr)   c                    R # )ae  Available commands:
cd path                         Change remote directory to 'path'.
chgrp gid path                  Change gid of 'path' to 'gid'.
chmod mode path                 Change mode of 'path' to 'mode'.
chown uid path                  Change uid of 'path' to 'uid'.
exit                            Disconnect from the server.
get remote-path [local-path]    Get remote file.
help                            Get a list of available commands.
lcd path                        Change local directory to 'path'.
lls [ls-options] [path]         Display local directory listing.
lmkdir path                     Create local directory.
ln linkpath targetpath          Symlink remote file.
lpwd                            Print the local working directory.
ls [-l] [path]                  Display remote directory listing.
mkdir path                      Create remote directory.
progress                        Toggle progress bar.
put local-path [remote-path]    Put local file.
pwd                             Print the remote working directory.
quit                            Disconnect from the server.
rename oldpath newpath          Rename remote file.
rmdir path                      Remove remote directory.
rm path                         Remove remote file.
version                         Print the SFTP version.
?                               Synonym for 'help'.
r3   r  s   &&r&   r   StdioClient.cmd_HELP  s    r)   c                    V P                   # r=   r   r  s   &&r&   cmd_PWDStdioClient.cmd_PWD  s    $$$r)   c                ,    \         P                  ! 4       # r=   )r   getcwdr  s   &&r&   cmd_LPWDStdioClient.cmd_LPWD  s    yy{r)   c                |    V P                   '       * V n         R V P                   ;'       d    R;'       g    R,          # )z%ssing progess bar.UzNot u)r   r  s   &&r&   cmd_PROGRESSStdioClient.cmd_PROGRESS  s4    "&"5"55$(;(;(C(C(N(NwOOr)   c                    V P                   P                  \        P                  ! 4       4      ^,          pV'       g   RpV'       d   RV.p\        P
                  ! W#^R7      # \        P                  ! V4       R# )zJ
Run C{rest} using the user's shell (or /bin/sh if they do not have
one).
z/bin/shz-c)errortooN)_pwdgetpwnamrk   rl   r   getProcessOutputr   r  )r%   r   shellcmdss   &&  r&   r   StdioClient.cmd_EXEC  sW    
 		""7??#45a8E$<D))%BBIIer)   c                   \         P                  ! R V,          4       \        P                  P	                  V4      w  r#RV9   g   RV9   d   ^pM^ pV'       d^   V'       gV   V P
                  P                  V4      pVP                  V P                  R4       VP                  V P                  W#4       V# V P
                  P                  V4      pVP                  V P                  V4       V# )zlooking up %sr
  r  r   )r   r   r   r   r#   r   r   r   _cbOpenListrp   _ebNotADirectory)r%   r  headtailrW  r   s   &&    r&   r  StdioClient._remoteGlob  s    (*+WW]]8,
$;#+DD))(3AMM$**B/LL..;  ))$/AMM$**D1r)   c                d    . pVP                  4       pVP                  V P                  W1V4       V# r=   )rv  r"  _cbReadFile)r%   r   rW  r  r   s   &&&  r&   r  StdioClient._cbOpenList  s.    NN			$""Ed;r)   c                t    V P                   P                  V4      pVP                  V P                  V4       V# r=   )r   r   r   r  )r%   rM  r   rW  r   s   &&&& r&   r  StdioClient._ebNotADirectory  s/    KK%%d+	d&&-r)   c           	        \        V\        P                  4      '       g   V'       d[   VP                  ! R 4      pTP	                  V Uu. uF+  p\
        P
                  ! V^ ,          V4      '       g   K)  VNK-  	  up4       MVP	                  V4       VP                  4       pVP                  V P                  W#V4       V# TpVP                  \        4       VP                  4        V# u upi r   )r   r   re   r   extendfnmatchrv  r"  r  r   rG  r   )r%   r  matchedFilesr   rW  rx   r   rM  s   &&&&&   r&   r  StdioClient._cbReadFile  s    %11{{7+##$U11t9TQQ$UV##E* AIId&&FHFKK!OO %Vs   
&C,5C,c                ^    . ROpV F  w  r4W8  g   K   M	  RVX,          ,          X,           # )rN   z%.1f))l           PB)l        TB)i   @GB)i   MB)i   kB)rN   r4   r3   )r%   r   _abbrevsfactorsuffixs   &&   r&   _abbrevSizeStdioClient._abbrevSize
  s5    
 'NF} ' '&00r)   c                   VR 8  dP   \        VR ,          4      pVR V,          ,          p\        V^<,          4      pV^<V,          ,          pRW#V3,          # \        V^<,          4      pV^<V,          ,          pRW13,          # )i  z%i:%02i:%02iz	%02i:%02i)r.   )r%   thoursminss   &&  r&   _abbrevTimeStdioClient._abbrevTime  su    t8DMEAq2v;DdNA!U!$444q2v;DdNA$**r)   c                   V P                   P                  4       V,
          pVP                  p \        P                  ! R\
        P                  ! ^ \        P                  R4      4      pVR8X  d   RpMWC,          pV'       d   VP                  V,
          V,          pM^ pVP                  pVP                  '       d   WAP                  ,          ^d,          p	M^dp	RV	V P                  V4      V P                  V4      V P                  V4      3,          p
V^,          \        V4      \        V
4      ,           ^,           ,
          R,          pRV V V
 2pV P                  V4       R#   \         d	    R^P.p ELi ; i)a  
Update a console progress bar on this L{StdioClient}'s transport, based
on the difference between the start time of the operation and the
current time according to the reactor, and appropriate to the size of
the console window.

@param f: a wrapper around the file which is being written or read
@type f: L{FileWrapper}

@param startTime: The time at which the operation being tracked began.
@type startTime: L{float}
4H12345679Nr~   z%3i%% %s %sps %s r   )r   r0  r   structunpackfcntlioctltty
TIOCGWINSZr   r   r   r  r  rH  r   )r%   rx   r:  diffr   winSizespeedtimeLeftfront
percentagebackspacesr   s   &&&          r&   rI  StdioClient._printProgressBar&  s?    ||##%	1	!mmD%++a*TUG 3;ELE%/HH666&&.C/JJ"U#U#X&	&
 
 !*E
SY 6 :;sBugfXdV,w'/  	!RjG	!s   ;E( (E;:E;c                   VP                  4       pV'       g   R# V^ ,          R9   d   . p\        V4      p \        ^\        V4      4       F  pW,          pWA^ ,          8X  d<   RP	                  V4      RP	                  W^,           R 4      P                  4       3u # VR8X  d=   W W,          R9  d   \        RW,           24      hVP                  W,          4       K  VP                  W,          4       K  	  VP                  R^4      p\        V4      ^8X  d   V^ ,          R3# V^ ,          V^,          3#   \         d    \        R4      hi ; i)	a  
Parse line received as command line input and return first filename
together with the remaining line.

@param line: Arguments received from command line input.
@type line: L{str}

@return: Tupple with filename and rest. Return empty values when no path was not found.
@rtype: C{tupple}
r   z'"N\z'"\zbad quote: \zunterminated quote)r   r   )	r   listr1  rH  r   r   
IndexErrorr3  r#   )r%   r   retr]   cs   &&   r&   r   StdioClient._getFilenameP  s(    zz|M7eC:D7q#d),AAG|!wws|RWWTa%']-C-J-J-LLLd G7'1",}TWI-F"GG

47+

47+ - jjq!s8q=q62:q63q6>!  7 !5667s   A'D< AD< <E)r   r   r   r   r   r=   )NN)F)Gr>   r?   r@   rA   pwdr  r   	delimiterr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r  r  r  r  r  r(  rD  r2  r5  rZ  rY  rX  r_  re  rn  rr  rs  r}  r  r  r  r  r  r  r  r  r  r  cmd_QUITr  r   r  r  r  r   r  r  r  r  r  r  rI  r   rI   rJ   rK   s   @r&   r   r      sW    D	BIG1@)
*((
+-%0;$F&<56>K<3j&5O2%H
F
%A
"M/ H6%P "
  1 
+((T#" #"r)   r   zcmd_?c                   &   a  ] tR tRt o R tRtV tR# )rm   iy  c                8    V P                  \        4       4       R # r=   )openChannel
SSHSessionr   s   &r&   serviceStartedSSHConnection.serviceStartedz  s    &r)   r3   N)r>   r?   r@   rA   r  rI   rJ   rK   s   @r&   rm   rm   y  s     ' 'r)   rm   c                      a  ] tR tRt o Rt]P                  tR tR tV 3R lR lt	R t
R tR	 tR
 tR tV 3R ltRtV tR# )r  i~  s   sessionc                   \         P                  ! R V P                  ,          4       V P                  P                  R,          P                  R4      '       d   RpMRpV P                  P                  W\        P                  ! V P                  P                  R,          4      ^R7      pVP                  V P                  4       VP                  \        4       R# )zsession %s openr:   r    exec)	wantReplyN)r   r   idrr   r   r   sendRequestr
   NSr   _cbSubsystemrp   rq   )r%   foorequestr   s   &&  r&   channelOpenSSHSession.channelOpen  s    !DGG+,99[)44S99G!GII!!699TYY%6%6{%CDPQ " 
 	
d''(	Wr)   c                   \         P                  ! 4       V n        V P                  P                  V 4       V P                  P                  V n        R pV P
                  P                  R,          '       d0   V P
                  P                  R,          pVR8w  d   \        V4      p\        P                  ! \        V P                  V4      4      V n        R # )Nr5   r   )r   FileTransferClientr   makeConnectiondataReceivedrr   r   r  r   
StandardIOr   )r%   r   rx   fns   &&  r&   r!  SSHSession._cbSubsystem  s    "557""4( KK4499[))"";/BSyH%%k$++q&AB
r)   c                *   < V ^8  d   QhRS[ RS[RR/# )r+   r  rK  returnN)r.   r   )r/   r0   s   "r&   r1   SSHSession.__annotate__  s"     9  9 S 9  9 $ 9 r)   c                
   V\         P                  8X  dn   \        P                  ! R \	        V4      ,          4       V P
                  P                  VP                  RR4      4       V P
                  P                  4        R# R# )zgot %s stderr datar   backslashreplaceN)	r   EXTENDED_DATA_STDERRr   r   rH  rX   r   r   flush)r%   r  rK  s   &&&r&   extReceivedSSHSession.extReceived  s]    
///GG(3t945l KKdkk'3EFGKKq 0r)   c                f    \         P                  ! R 4       V P                  P                  4        R# )zgot eofN)r   r   r   loseWriteConnectionr   s   &r&   eofReceivedSSHSession.eofReceived  s    	

&&(r)   c                v    \         P                  ! R V ,          4       V P                  P                  V 4       R# )zremote side closed %sN)r   r   rr   	sendCloser   s   &r&   closeReceivedSSHSession.closeReceived  s&    '$./		D!r)   c                V     \         P                  ! 4        R #   \         d     R # i ; ir=   )r   rb   rc   r   s   &r&   closedSSHSession.closed  s"    	LLN 		s    ((c                :    V P                   P                  4        R # r=   )r   pauseProducingr   s   &r&   stopWritingSSHSession.stopWriting  s    

!!#r)   c                :    V P                   P                  4        R # r=   )r   resumeProducingr   s   &r&   startWritingSSHSession.startWriting  s    

""$r)   c                2   < V ^8  d   Qh/ S[ ;R&   S[;R&   # )r+   r   rX   )r   r   )r/   r0   s   "r&   r1   r/  ~  s     
  r)   )r   r)  r   N)r>   r?   r@   rA   r   rO   rX   r$  r!  r4  r8  r<  r?  rC  rG  rH   rI   rJ   rK   s   @r&   r  r  ~  sJ     DZZF
	C9  9 v)"$%O  r)   r  __main__)6__doc__r  r  rk   rW  r   r  r.  r  rO   r  typingr   r   r   r   twisted.conch.clientr   r   r   twisted.conch.sshr	   r
   r   r   twisted.internetr   r   r   r   twisted.protocolsr   twisted.pythonr   r   r   twisted.python.filepathr   ConchOptionsr   r[   rf   rZ   rq   rz   r|   LineReceiverr   setattrr   rm   
SSHChannelr  r>   r3   r)   r&   <module>rW     s   
     	 
   
 
 0 0 : : G G 9 9 # . . ,&G(( &D,
G&		% %f"%$$ f"R Wk22 3'J,, '
h%## h%V zE r)   