o ¯b•zã@szdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z m Z mZddlmZmZmZddlmZmZmZmZddlmZmZmZmZddlmZddlm Z m!Z!m"Z"dd l#m$Z$Gd d „d ej%ƒZ&d d „Z'dd„Z(dd„Z)dd„Z*dd„Z+Gdd„dƒZ,Gdd„dej-ƒZ.e/e.de.j0ƒGdd„dej1ƒZ1Gdd„dej2ƒZ3e4dkr»e'ƒdSdS) z0 Implementation module for the I{cftp} command. éN)ÚListÚOptionalÚUnion)ÚconnectÚdefaultÚoptions)ÚchannelÚcommonÚ connectionÚ filetransfer)ÚdeferÚreactorÚstdioÚutils)Úbasic)ÚfailureÚlogÚusage)ÚFilePathc@szeZdZUdZdZgd¢gd¢gd¢gd¢gZeeeee e fe d<e j dd ie  ¡e jd d gd Zddd„Zd S)Ú ClientOptionszˆUsage: 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)Ú buffersizeÚ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.Ú optParametersrz,Size of send/receive buffer (default: 32768)z local file)Údescr)Ú descriptionsÚ extraActionsNcCsFd|d<d|vr| dd¡\}|d<|d d¡||d<||d<dS)NÚÚ remotePathú:éú/ÚhostÚ localPath)ÚsplitÚrstrip)Úselfr)r*©r.ú)Ú exitStatusr ÚstopÚ BaseExceptionrÚerrrÚFailurer.r.r.r/Ú handleErrorUs  ÿrVcCs¶d|dvr|d dd¡\|d<|d<|d}|ds"t ¡|d<|ds+d|d<nt|dƒ|d<|d}|d}tƒ}||_tj}t |d||¡}t   |||||¡  t ¡dS)Nú@r)r'ÚuserÚporté) r+ÚgetpassÚgetuserr8Ú SSHConnectionrrÚ verifyHostKeyÚSSHUserAuthClientrÚ addErrbackÚ_ebExit)rr)rYÚconnÚvhkÚuaor.r.r/rK`s   rKcCsJt|jdƒr |jj}nt|ƒ}t|ƒzt ¡WdSty$YdSw)NÚvalue)Úhasattrrer7rEr rRrS)Úfrr.r.r/rass   ÿracGsdSr1r.)rMr.r.r/Ú_ignoreórhc@seZdZdd„Zdd„ZdS)Ú FileWrappercCs&||_d|_| dd¡| ¡|_dS)Nçrr>)rgÚtotalÚseekÚtellÚsize©r-rgr.r.r/Ú__init__„s zFileWrapper.__init__cCs t|j|ƒSr1)Úgetattrrg)r-Úattrr.r.r/Ú __getattr__Šs zFileWrapper.__getattr__N)r2r3r4rqrtr.r.r.r/rjƒs rjc@sþeZdZeZdZdZeZd{dd„Zdd„Z dd „Z d d „Z d d „Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd|d$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Z d6d7„Z!d8d9„Z"d:d;„Z#ddqdr„Z?dsdt„Z@dudv„ZAdwdx„ZBdydz„ZCdS)~Ú StdioClientzcftp> ó NcCs&||_d|_||_| rdpd|_dS)Nr$r'r)ÚclientÚcurrentDirectoryÚfileÚuseProgressBar)r-rwrgr.r.r/rq—szStdioClient.__init__cCs|j d¡ |j¡dS)Nr$)rwÚrealPathÚ addCallbackÚ _cbSetCurDir©r-r.r.r/ÚconnectionMadeszStdioClient.connectionMadecCs||_| ¡dSr1)rxÚ_newLine©r-Úpathr.r.r/r} s zStdioClient._cbSetCurDircCs t|tƒr | d¡}|j |¡S)Núutf-8)Ú isinstancer7ÚencodeÚ transportÚwrite)r-Úmsgr.r.r/Ú_writeToTransport¤s   zStdioClient._writeToTransportcCs¤|jjjrdSt|tƒr| d¡}t d|¡| ¡}|s$|  ¡dS|j r6|  d¡r6d|_ |dd…}nd|_ |  |¡}|durP| |j¡| |j¡dSdS)Nrƒz got line %sú-r'r)rwr†Ú localClosedr„ÚbytesÚdecoderrˆÚlstripr€ryÚ startswithÚ ignoreErrorsÚ_dispatchCommandr|Ú _cbCommandr`Ú _ebCommand)r-ÚlineÚdr.r.r/Ú lineReceived©s$     þzStdioClient.lineReceivedcCs¸d|vr| dd¡\}}| ¡}n|d}}| d¡r+|j}|dd…d| ¡}n| ¡}t d|¡t|d|dƒ}|durHt   ||¡Sd|}|  t   t|ƒ¡¡| ¡dS)Nú r'r$ú!zlooking up cmd %szcmd_%szNo command called `%s')r+rŽrÚcmd_EXECÚstripÚupperrrˆrrr Ú maybeDeferredr“rrUÚNotImplementedErrorr€)r-r”ÚcommandÚrestrgÚerrMsgr.r.r/r‘½s     zStdioClient._dispatchCommandcCs–t |¡| ttjtt¡}|tkr| |  d¡¡dS|tjkr2d|j j |j j f}| |¡dS|ttfvrId|j j |j jf}| |¡dSdS)Nr$zremote error %i: %s zlocal error %i: %s )rrˆÚtraprr Ú SFTPErrorÚOSErrorÚIOErrorr‰Úcmd_HELPreÚcodeÚmessageÚerrnoÚstrerror)r-rgÚer r.r.r/Ú _printFailureÑs   þzStdioClient._printFailurecCsd|jjjrdS| |j¡d|_|jr0|j ¡}|s"|jj ¡dS| |¡|  |  ¡¡dSdS)Nr) rwr†r‹r‰ÚpsrryÚreadlineÚloseConnectionr–rš)r-Úlr.r.r/r€Ýs    úzStdioClient._newLinecCsF|durt|tƒr| d¡}| |¡| d¡s| d¡| ¡dS)Nrƒrv)r„r7r…r‰Úendswithr€)r-Úresultr.r.r/r’ês      zStdioClient._cbCommandcCs.| |¡|jr|js|jj ¡| ¡dSr1)r«ryrrwr†r®r€rpr.r.r/r“ós    zStdioClient._ebCommandcCs`| |¡\}}| d¡s|d7}|rtj |j|¡pd}|j |¡}| |j ¡|  |j ¡|S)Nr(r$) Ú _getFilenamer°Úosr‚ÚjoinrxrwÚ openDirectoryr|Ú_cbCdr`r“)r-r‚rŸÚnewPathr•r.r.r/Úcmd_CDùs    zStdioClient.cmd_CDcCs&| ¡|j |j¡}| |j¡|Sr1)Úcloserwr{Únamer|Ú _cbCurDir)r-Ú directoryr•r.r.r/r¶s zStdioClient._cbCdcCs ||_dSr1©rxrr.r.r/r» s zStdioClient._cbCurDircCóH| dd¡\}}| |¡\}}t|ƒ}|j |¡}|j|j||d|S)Nr')Úgrp©r+r²r8rwÚgetAttrsr|Ú _cbSetUsrGrp)r-rŸr¿r‚r•r.r.r/Ú cmd_CHGRP ó  zStdioClient.cmd_CHGRPcCsH| dd¡\}}| |¡\}}t|dƒ}|j |d|i¡}| t¡|S)Nr'éÚ permissions)r+r²r8rwÚsetAttrsr|rh)r-rŸÚmodr‚r•r.r.r/Ú cmd_CHMODs   zStdioClient.cmd_CHMODcCr¾)Nr')ÚusrrÀ)r-rŸrÊr‚r•r.r.r/Ú cmd_CHOWNrÄzStdioClient.cmd_CHOWNcCsPi}|dur|p |d|d<|dur|p|d|d<|j ||¡}| t¡|S)NÚuidÚgid)rwrÇr|rh)r-Úattrsr‚rÊr¿Únewr•r.r.r/rÂ$s  zStdioClient._cbSetUsrGrpcCsä| |¡\}}d|vsd|vr1|r!| |¡\}}tj |¡s dSnd}| |¡}| |j|¡|S|r;| |¡\}}ntj |¡d}t  ||f¡t |ddƒ}t |j ƒ  |¡}|j |jtji¡}| |j|¡| |j|¡|S)NÚ*ú?z'Wildcard get with non-directory target.ór'Úwbr)r²r³r‚ÚisdirÚ _remoteGlobr|Ú_cbGetMultipler+rrˆÚopenrrxÚchildrwÚopenFiler ÚFXF_READÚ_cbGetOpenFiler`Ú _ebCloseLf)r-rŸÚremoteÚlocalr•Úlfr‚r.r.r/Úcmd_GET,s* ÿ  zStdioClient.cmd_GETcCs| d||¡Sr1)Ú_cbGetMultipleNext)r-ÚfilesrÞr.r.r/rÖDszStdioClient._cbGetMultiplecCsÆt|tjƒr | |¡n|r| |¡| d¡s| d¡|s!dS| d¡d}ttj   |tj   |¡d¡ddƒ}t |j ƒ |¡}|j |j tji¡}| |j|¡| |j|¡| |j||¡|S)NÚ rr'rÓ)r„rrUr«r‰r°Úpopr×r³r‚r´r+rrxrØrwrÙr rÚr|rÛr`rÜÚaddBothrá)r-ÚresrârÞrgrßr‚r•r.r.r/ráHs     "zStdioClient._cbGetMultipleNextcCs | ¡|Sr1)r¹)r-rgrßr.r.r/rÜZszStdioClient._ebCloseLfcCs| ¡ |j||¡Sr1)rÁr|Ú_cbGetFileSize)r-Úrfrßr.r.r/rÛ^szStdioClient._cbGetOpenFilec Csºt |d¡s| ¡| ¡d|jS|d|_|jjjjd}|jjjjd}d|_ g}g}|j   ¡}t |ƒD]} |  d|||d||¡} | | ¡q9tj|d d } |  |j||¡| S) NrÆzCan't get non-regular file: %srorrrkr$rr'©ÚfireOnOneErrback)ÚstatÚS_ISREGr¹rºrorwr†rbrrlr ÚsecondsÚrangeÚ _cbGetReadÚappendr Ú DeferredListr|Ú _cbGetDone) r-rÎrèrßÚ bufferSizeÚ numRequestsÚdListÚchunksÚ startTimerNr•Údlr.r.r/rças"     zStdioClient._cbGetFileSizecCsd}|D],}|dkr dS||dkr,| |¡}| |||df¡||d|fS|d}qt|jjjjdƒ}| |||f¡||fS)NrÚeofr'r)rBÚinsertr8rwr†rbrrð)r-röÚendÚchunkrNÚbufSizer.r.r/Ú _getNextChunkts   zStdioClient._getNextChunkc CsN|r+t|tjƒr+t d|¡|}| t¡| |||f¡} || =| | |df¡nG|rrt dt |ƒ¡|  |¡|  |¡t |ƒ|krit dt |ƒ|f¡| |||f¡} || =| | ||t |ƒf¡|j t |ƒ7_ |j r{| ||¡| |¡} | s„dS| \}} t d||| f¡| || ¡} |  |j||||| |¡| S)Nzget read err: %srùzget read data: %iz#got less than we asked for: %i < %izasking for %i -> %i)r„rrUrrˆr¡ÚEOFErrorrBrúÚlenrmr‡rlrzÚ_printProgressBarrþÚ readChunkrårï) r-ÚdatarèrßröÚstartror÷ÚreasonrNrüÚlengthr•r.r.r/rï‚s6       zStdioClient._cbGetReadcCs>t d¡| ¡| ¡|jr| d¡d|j›d|j›S)Nzget donerãú Transferred ú to )rrˆr¹rzr‰rº©r-Úignoredrèrßr.r.r/rò s  zStdioClient._cbGetDonecCsŒ| |¡\}}d|vsd|vr.|r!| |¡\}}tj |j|¡}nd}t |¡}| ||¡S|r8| |¡\}}ntj |¡d}| ||¡S)a# 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´rxÚglobÚ_putMultipleFilesr+Ú_putSingleFile)r-rŸrÞrÝrâr.r.r/Úcmd_PUT¨s    zStdioClient.cmd_PUTcCs|jd|g|ddS)aB 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Ýr.r.r/r Çs zStdioClient._putSingleFilecCs| d||¡S)aV 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Ýr.r.r/r Ös zStdioClient._putMultipleFilesFc Cst|tjƒr | |¡n|r't|tƒr| d¡}| |¡| d¡s'| d¡d}|rP|sPz | d¡}t |dƒ}Wnt yK| t ¡¡d}Ynw|rP|r-|sTdS|rY|}nt j   |¡d}t j  ||¡}t |||f¡| ||¡} |  |j||¡| S)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ƒrvNrÚrbr')r„rrUr«r7r…r‰r°rär×rSr³r‚r+r´rrˆÚ_putRemoteFilerår) r-ÚpreviousResultrâr%rÚ currentFileÚ localStreamrÝrºr•r.r.r/rås8         þü  zStdioClient._cbPutMultipleNextcCsRtj |j|¡}tjtjBtjB}|j  ||i¡}|  |j |¡|  |j |¡|S)aW 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´rxr Ú FXF_WRITEÚ FXF_CREATÚ FXF_TRUNCrwrÙr|Ú_cbPutOpenFiler`rÜ)r-rr%rÝÚflagsr•r.r.r/rs  zStdioClient._putRemoteFilec Cs€|jjjjd}|jrt|ƒ}g}g}|j ¡}t|ƒD]}|  d||||¡}|r.|  |¡qt j |dd} |   |j||¡| S)Nrr'ré)rwr†rbrrzrjr rírîÚ _cbPutWriterðr rñr|Ú _cbPutDone) r-rèrßrôrõrör÷rNr•rør.r.r/r-s   €zStdioClient._cbPutOpenFilec Csv| |¡}|\}}| |¡| |¡} |jr%|jt| ƒ7_| ||¡| r9| || ¡} |  |j ||||¡| SdSr1) rþrmÚreadrzrlrrÚ writeChunkr|r) r-r rèrßrör÷rürrorr•r.r.r/r<s     zStdioClient._cbPutWritecCs4| ¡| ¡|jr| d¡d|j›d|j›S)Nrãrr)r¹rzr‰rºr r.r.r/rKs  zStdioClient._cbPutDonecCst |¡dSr1)r³Úchdirrr.r.r/Úcmd_LCDRózStdioClient.cmd_LCDcóJˆ |¡\}}ˆ |¡\}}t‡fdd„||fƒ\}}ˆj ||¡ t¡S)Ncótj ˆj|¡Sr1©r³r‚r´rx©Úxr~r.r/ÚYóz$StdioClient.cmd_LN..)r²ÚmaprwÚmakeLinkr|rh)r-rŸÚlinkpathÚ targetpathr.r~r/Úcmd_LNUó ÿzStdioClient.cmd_LNcCsÚg}| ¡}|rC|drC|dddkrC| d¡dd…}|D]}|dkr+| d¡q|dkr4| d¡q|rC|drC|dddksd |¡}| |¡\}}|sW|jd }ntj |j|¡}| |¡}|  |j |¡|S) NrrŠr'r¯ÚverboseÚaÚallr—r() r+rärðr´r²rxr³r‚rÕr|Ú_cbDisplayFiles)r-rŸrÚoptsÚor‚ÚfullPathr•r.r.r/Úcmd_LS]s&  €ú   zStdioClient.cmd_LScCsV| ¡d|vrdd„|Dƒ}d|vrdd„|Dƒ}ndd„|Dƒ}|s&dSd |¡S)Nr2cSsg|] }|d d¡s|‘qS)ró.)r©Ú.0rgr.r.r/Ú ysz/StdioClient._cbDisplayFiles..r0cSóg|]}|d‘qS)r'r.r9r.r.r/r;{ócSr<©rr.r9r.r.r/r;}r=rv)Úsortr´)r-rârÚlinesr.r.r/r3vs zStdioClient._cbDisplayFilescCs2| |¡\}}tj |j|¡}|j |i¡ t¡Sr1) r²r³r‚r´rxrwÚ makeDirectoryr|rh©r-r‚rŸr.r.r/Ú cmd_MKDIRƒszStdioClient.cmd_MKDIRcCó0| |¡\}}tj |j|¡}|j |¡ t¡Sr1) r²r³r‚r´rxrwÚremoveDirectoryr|rhrBr.r.r/Ú cmd_RMDIRˆózStdioClient.cmd_RMDIRcCót d|¡dS)Nzmkdir %s©r³Úsystemrr.r.r/Ú cmd_LMKDIRózStdioClient.cmd_LMKDIRcCrDr1) r²r³r‚r´rxrwÚ removeFiler|rhrBr.r.r/Úcmd_RMrGzStdioClient.cmd_RMcCrH)Nzls %srI)r-rŸr.r.r/Úcmd_LLS•rLzStdioClient.cmd_LLScr#)Ncr$r1r%r&r~r.r/r(œr)z(StdioClient.cmd_RENAME..)r²r*rwÚ renameFiler|rh)r-rŸÚoldpathÚnewpathr.r~r/Ú cmd_RENAME˜r/zStdioClient.cmd_RENAMEcCs|jj ¡dSr1)rwr†r®©r-r r.r.r/Úcmd_EXIT ózStdioClient.cmd_EXITcCs$d|jj}t|tƒr| d¡}|S)NzSFTP version %irƒ)rwÚversionr„r7r…)r-r rWr.r.r/Ú cmd_VERSION¥s   zStdioClient.cmd_VERSIONcCsdS)NaeAvailable 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'. r.rTr.r.r/r¥«rizStdioClient.cmd_HELPcCs|jSr1r½rTr.r.r/Úcmd_PWDÆszStdioClient.cmd_PWDcCst ¡Sr1)r³ÚgetcwdrTr.r.r/Úcmd_LPWDÉszStdioClient.cmd_LPWDcCs|j |_d|jr dp dS)Nz%ssing progess bar.ÚUzNot u)rzrTr.r.r/Ú cmd_PROGRESSÌs zStdioClient.cmd_PROGRESScCsF|j t ¡¡d}|sd}|rd|g}tj||ddSt |¡dS)zb Run C{rest} using the user's shell (or /bin/sh if they do not have one). éz/bin/shz-cr')ÚerrortooN)Ú_pwdÚgetpwnamr[r\rÚgetProcessOutputr³rJ)r-rŸÚshellÚcmdsr.r.r/r™ÐszStdioClient.cmd_EXECcCsŒt d|¡tj |¡\}}d|vsd|vrd}nd}|r7|s7|j |¡}| |jd¡|  |j ||¡|S|j |¡}| |j|¡|S)Nz looking up %srÐrÑr'rr$) rrˆr³r‚r+rwrµr|Ú _cbOpenListr`Ú_ebNotADirectory)r-r6ÚheadÚtailr r•r.r.r/rÕàs  þzStdioClient._remoteGlobcCs"g}| ¡}| |j|||¡|Sr1)rråÚ _cbReadFile)r-r¼r râr•r.r.r/reñszStdioClient._cbOpenListcCs|j |¡}| |j|¡|Sr1)rwrµr|re)r-rr‚r r•r.r.r/rf÷s zStdioClient._ebNotADirectorycsvt|tjƒs.ˆrˆ d¡‰| ‡fdd„|Dƒ¡n| |¡| ¡}| |j||ˆ¡|S|}| t ¡|  ¡|S)Nrƒcs g|] }t |dˆ¡r|‘qSr>)Úfnmatchr9©r r.r/r;s z+StdioClient._cbReadFile..) r„rrUr…Úextendrrårir¡rÿr¹)r-râÚ matchedFilesr¼r r•rr.rkr/riüs    zStdioClient._cbReadFilecCs2gd¢}|D] \}}||krnqd|||S)N))l ÚPB)lÚTB)i@ÚGB)iÚMB)iÚkB)r'rz%.1fr.)r-roÚ_abbrevsÚfactorÚsuffixr.r.r/Ú _abbrevSize s  ÿzStdioClient._abbrevSizecCsj|dkr#t|dƒ}|d|8}t|dƒ}|d|8}d|||fSt|dƒ}|d|8}d||fS)Nié<z %i:%02i:%02iz %02i:%02i)r8)r-ÚtÚhoursÚminsr.r.r/Ú _abbrevTimes       zStdioClient._abbrevTimec Csü|j ¡|}|j}zt dt dtjd¡¡}Wn t y%ddg}Ynw|dkr-d}n||}|r;|j ||}nd}|j }|j rK||j d} nd} d| |  |¡|  |¡|  |¡f} |d t|ƒt| ƒd d } d |›| ›| ›} | | ¡dS) 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} Ú4HrÚ12345679NéPrkédz%3i%% %s %sps %s r'r—ú )r rírlÚstructÚunpackÚfcntlÚioctlÚttyÚ TIOCGWINSZr£rorºrvr{rr‰) r-rgr÷ÚdiffrlÚwinSizeÚspeedÚtimeLeftÚfrontÚ percentageÚbackÚspacesržr.r.r/r(s4   ÿü zStdioClient._printProgressBarcCs| ¡}|sdS|ddvrpg}t|ƒ}zPtdt|ƒƒD]F}||}||dkr=d |¡d ||dd…¡ ¡fWS|dkr[||=||dvrStd ||›ƒ‚| ||¡q| ||¡qWn tyotd ƒ‚w| dd¡}t|ƒdkr‚|ddfS|d|dfS) aW 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$r$rz'"r'r$Nú\z'"\z bad quote: \zunterminated quote) ršÚlistrîrr´rŽÚ IndexErrorrðr+)r-r”ÚretrNÚcr.r.r/r²Rs2   * ö ÿ   zStdioClient._getFilenamer1)NN)F)Dr2r3r4Úpwdr`r¬Ú delimiterr rqrr}r‰r–r‘r«r€r’r“r¸r¶r»rÃrÉrËrÂràrÖrárÜrÛrçrþrïròrr r rrrrrr!r.r7r3rCrFrKrNrOrSrUÚcmd_QUITrXr¥rYr[r]r™rÕrerfrirvr{rr²r.r.r.r/ruŽs‚       5  *ruzcmd_?c@seZdZdd„ZdS)r]cCs| tƒ¡dSr1)Ú openChannelÚ SSHSessionr~r.r.r/ÚserviceStarted|rVzSSHConnection.serviceStartedN)r2r3r4r™r.r.r.r/r]{s r]c@sPeZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dS)r˜ssessioncCsht d|j¡|jjd d¡rd}nd}|jj||t |jjd¡dd}|  |j ¡|  t ¡dS)Nzsession %s openrr(Úexecr')Ú wantReply) rrˆÚidrbrrÚ sendRequestr ÚNSr|Ú _cbSubsystemr`ra)r-ÚfooÚrequestr•r.r.r/Ú channelOpen„sÿ zSSHSession.channelOpencCsdt ¡|_|j |¡|jj|_d}|jjdr&|jjd}|dkr&t|ƒ}t  t |j|ƒ¡|_dS)NrrŠ) r ÚFileTransferClientrwÚmakeConnectionÚ dataReceivedrbrr×rÚ StandardIOru)r-r±rgÚfnr.r.r/rŸs     zSSHSession._cbSubsystemcCs:|tjkrt dt|ƒ¡tj |¡tj ¡dSdS)Nzgot %s stderr data) r ÚEXTENDED_DATA_STDERRrrˆrr@rIr‡Úflush)r-rxrr.r.r/Ú extReceived›s  ýzSSHSession.extReceivedcCst d¡|j ¡dS)Nzgot eof)rrˆrÚloseWriteConnectionr~r.r.r/Ú eofReceived¡s zSSHSession.eofReceivedcCst d|¡|j |¡dS)Nzremote side closed %s)rrˆrbÚ sendCloser~r.r.r/Ú closeReceived¥szSSHSession.closeReceivedcCs$zt ¡WdStyYdSwr1)r rRrSr~r.r.r/Úclosed©s  ÿzSSHSession.closedcCó|j ¡dSr1)rÚpauseProducingr~r.r.r/Ú stopWriting¯r"zSSHSession.stopWritingcCr°r1)rÚresumeProducingr~r.r.r/Ú startWriting²r"zSSHSession.startWritingN) r2r3r4rºr¢rŸrªr¬r®r¯r²r´r.r.r.r/r˜€s   r˜Ú__main__)5Ú__doc__rƒrjr[r r³r”rërr@r…ÚtypingrrrÚtwisted.conch.clientrrrÚtwisted.conch.sshrr r r Útwisted.internetr r rrÚtwisted.protocolsrÚtwisted.pythonrrrÚtwisted.python.filepathrÚ ConchOptionsrrLrVrKrarhrjÚ LineReceiverruÚsetattrr¥r]Ú SSHChannelr˜r2r.r.r.r/ÚsJ  #   o6 ÿ