B v?ڄm@sRddlZddlZddlmZddddddgZd Zd Zd ZGd d d eZGdddeZ GdddeZ GdddeZ GdddeZ ee efZdZdZGdddZy ddlZWnek rdZYn0XejZGdddeZedee eejfZdaddZdaddZddZddZdd Z d(d#d$Z!d%d&Z"e#d'krNe"dS))N)_GLOBAL_DEFAULT_TIMEOUTFTP error_reply error_temp error_perm error_proto all_errorsi c@s eZdZdS)ErrorN)__name__ __module__ __qualname__rr)/opt/alt/python37/lib/python3.7/ftplib.pyr 9sr c@s eZdZdS)rN)r r rrrrrr:sc@s eZdZdS)rN)r r rrrrrr;sc@s eZdZdS)rN)r r rrrrrr<sc@s eZdZdS)rN)r r rrrrrr=sz s c@seZdZdZdZeZeZdZ dZ dZ dZ dZ dZddddedfddZd d Zd d Zd[ddZddZddZeZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Z d(d)Z!d*d+Z"d,d-Z#d.d/Z$d0d1Z%d\d2d3Z&d]d4d5Z'd^d6d7Z(d_d9d:Z)d`d;d<Z*dad=d>Z+dbd?d@Z,dAdBZ-dCdDZ.dEdFZ/dgfdGdHZ0dIdJZ1dKdLZ2dMdNZ3dOdPZ4dQdRZ5dSdTZ6dUdVZ7dWdXZ8dYdZZ9dS)crrNr zlatin-1FcCs0||_||_|r,|||r,||||dS)N)source_addresstimeoutconnectlogin)selfhostuserpasswdacctrrrrr__init__rs  z FTP.__init__cCs|S)Nr)rrrr __enter__{sz FTP.__enter__c GsN|jdk rJz*y |Wnttfk r0YnXWd|jdk rH|XdS)N)sockquitOSErrorEOFErrorclose)rargsrrr__exit__s    z FTP.__exit__cCs|dkr||_|dkr||_|dkr*||_|dk r8||_tj|j|jf|j|jd|_|jj|_|jj d|j d|_ | |_ |j S)Nrri)rr)encoding)rportrrsocketcreate_connectionrZfamilyafmakefiler&filegetrespwelcome)rrr'rrrrrrs   z FTP.connectcCs|jrtd||j|jS)Nz *welcome*) debuggingprintsanitizer.)rrrr getwelcomeszFTP.getwelcomecCs ||_dS)N)r/)rlevelrrrset_debuglevelszFTP.set_debuglevelcCs ||_dS)N) passiveserver)rvalrrrset_pasvsz FTP.set_pasvcCsJ|dddkrBt|d}|ddd|d||d}t|S)N>PASS pass z *)lenrstriprepr)rsirrrr1s$z FTP.sanitizecCsRd|ksd|krtd|t}|jdkr:td|||j||jdS)N  z4an illegal newline character should not be containedr z*put*) ValueErrorCRLFr/r0r1rsendallencoder&)rlinerrrputlines  z FTP.putlinecCs$|jrtd||||dS)Nz*cmd*)r/r0r1rH)rrGrrrputcmdsz FTP.putcmdcCs|j|jd}t||jkr.td|j|jdkrHtd|||sPt|ddt krn|dd}n|ddt kr|dd}|S)Nr zgot more than %d bytesz*get*) r,readlinemaxliner<r r/r0r1r rD)rrGrrrgetlines  z FTP.getlinecCsd|}|dddkr`|dd}x:|}|d|}|dd|kr&|dddkr&Pq&W|S)N-rB)rN)rrGcodeZnextlinerrr getmultilines  zFTP.getmultilinecCsp|}|jrtd|||dd|_|dd}|dkrD|S|dkrTt||dkrdt|t|dS)Nz*resp*rOr >23145)rSr/r0r1Zlastresprrr)rrespcrrrr-s z FTP.getrespcCs$|}|dddkr t||S)Nr rT)r-r)rrYrrrvoidrespsz FTP.voidrespcCsTdt}|jdkr"td|||j|t|}|dddkrPt||S)NsABORr z *put urgent*rO>226225426) B_CRLFr/r0r1rrEMSG_OOBrSr)rrGrYrrraborts z FTP.abortcCs|||S)N)rIr-)rcmdrrrsendcmds z FTP.sendcmdcCs|||S)N)rIr[)rrbrrrvoidcmds z FTP.voidcmdcCsB|d}t|dt|dg}||}dd|}||S)N.zPORT ,)splitr>joinrd)rrr'ZhbytesZpbytesbytesrbrrrsendports  z FTP.sendportcCsbd}|jtjkrd}|jtjkr$d}|dkr4tddt||t|dg}dd|}||S)Nrr zunsupported address familyrzEPRT |)r*r(AF_INETZAF_INET6rr>rird)rrr'r*Zfieldsrbrrrsendeprt$s  z FTP.sendeprtc Csd}d}xtdd|jtjdtjD]j}|\}}}}}yt|||}||Wn8tk r} z| }|rt|d}w$Wdd} ~ XYnXPq$W|dkr|dk r|ntd|d| d} |j d} |jtj kr| | | } n | | | } |jtk r||j|S)Nrz!getaddrinfo returns an empty listr )r(Z getaddrinfor*Z SOCK_STREAMZ AI_PASSIVEZbindrr!ZlistenZ getsocknamerrnrkrorr settimeout) rerrrZresr*ZsocktypeprotoZ canonnameZsa_r'rrYrrrmakeport1s6       z FTP.makeportcCs\|jtjkr:t|d\}}|jr*|}qT|jd}nt|d|j\}}||fS)NPASVrZEPSV) r*r(rnparse227rctrust_server_pasv_ipv4_addressrZ getpeernameparse229)rZuntrusted_hostr'rrrrmakepasvQs z FTP.makepasvc Cs6d}|jr|\}}tj||f|j|jd}yL|dk rF|d|||}|ddkrd|}|ddkrxt|Wn| YnXn| r}|dk r|d|||}|ddkr|}|ddkrt|| \}} |jt k r | |jWdQRX|dddkr.t|}||fS)N)rzREST %srrTrVrO150)r5ryr(r)rrrcr-rr!rtZacceptrrpparse150) rrbrestsizerr'connrYrZsockaddrrrr ntransfercmd]s<             zFTP.ntransfercmdcCs|||dS)Nr)r)rrbr|rrr transfercmdszFTP.transfercmdcCs|sd}|sd}|sd}|dkr0|dkr0|d}|d|}|ddkrX|d|}|ddkrr|d |}|dd krt||S) NZ anonymousr>rrQz anonymous@zUSER rrUzPASS zACCT rT)rcr)rrrrrYrrrrs    z FTP.login c Csb|d|||>}x||}|s*P||qWtdk rPt|trP|WdQRX|S)NzTYPE I)rdrZrecv _SSLSocket isinstanceunwrapr[)rrbcallback blocksizer|r~datarrr retrbinarys   zFTP.retrbinaryc Cs|dkr t}|d}||}|jd|jd}x||jd}t||jkrbtd|j|j dkrzt dt ||sP|ddt kr|dd}n|d dd kr|dd }||q6Wt dk rt|t r|WdQRXWdQRX|S) NzTYPE Ar%)r&r zgot more than %d bytesrlz*retr*rJrKrB) print_linercrr+r&rLrMr<r r/r0r>rDrrrr[)rrbrrYr~fprGrrr retrliness*      z FTP.retrlinesc Csp|d|||L}x*||}|s*P|||r||qWtdk r^t|tr^|WdQRX|S)NzTYPE I)rdrreadrErrrr[)rrbrrrr|r~bufrrr storbinarys    zFTP.storbinaryc Cs|d||}x|||jd}t||jkrDtd|j|sJP|ddtkrz|dtkrr|dd}|t}|||r||qWtdk rt |tr| WdQRX| S)NzTYPE Ar zgot more than %d bytesrJrK) rdrrLrMr<r r_rErrrr[)rrbrrr~rrrr storlines s$     z FTP.storlinescCsd|}||S)NzACCT )rd)rZpasswordrbrrrr+szFTP.acctcGs4d}x|D]}|d|}q Wg}|||j|S)NZNLST )rappend)rr"rbargfilesrrrnlst0s  zFTP.nlstcGsld}d}|ddr>t|dtdkr>|dd|d}}x|D]}|rD|d|}qDW|||dS)NZLISTrKrr)typer)rr"rbfuncrrrrdir9s  zFTP.dirc cs|r|dd|d|r*d|}nd}g}|||jxh|D]`}|td\}}}i} x6|dddD] } | d\} }} | | | <qxW|| fVqFWdS)Nz OPTS MLST ;zMLSD %sZMLSDrrK=) rcrirrr=rD partitionrhlower) rpathZfactsrblinesrGZ facts_foundrsnameentryZfactkeyvaluerrrmlsdHs   zFTP.mlsdcCs0|d|}|ddkr"t||d|S)NzRNFR rrUzRNTO )rcrrd)rZfromnameZtonamerYrrrrenameds z FTP.renamecCs.|d|}|dddkr"|St|dS)NzDELE rO>250200)rcr)rfilenamerYrrrdeleteksz FTP.deletec Csn|dkrPy |dStk rL}z|jddddkr<Wdd}~XYq\Xn |dkr\d}d|}||S) Nz..ZCDUPrrO500rrezCWD )rdrr")rdirnamemsgrbrrrcwdss zFTP.cwdcCs:|d|}|dddkr6|dd}t|SdS)NzSIZE rOZ213)rcstripint)rrrYr?rrrr}szFTP.sizecCs$|d|}|dsdSt|S)NzMKD 257r)rd startswithparse257)rrrYrrrmkds zFTP.mkdcCs|d|S)NzRMD )rd)rrrrrrmdszFTP.rmdcCs |d}|dsdSt|S)NZPWDrr)rdrr)rrYrrrpwds  zFTP.pwdcCs|d}||S)NZQUIT)rdr!)rrYrrrrs zFTP.quitcCsDz |j}d|_|dk r|Wd|j}d|_|dk r>|XdS)N)r,r!r)rr,rrrrr!s z FTP.close)rrr$N)N)N)rrr)rN)N)rNN)N):r r rr/rFTP_PORTr'MAXLINErMrr,r.r5r&rwrrrr#rr2r4debugr7r1rHrIrNrSr-r[rarcrdrkrortryrrrrrrrrrrrrrrr}rrrrr!rrrrrJsj      7    #      c @sjeZdZejZdddddddedf ddZdddZdd Z d d Z d d Z ddZ dddZ ddZdS)FTP_TLSrNc Cs|dk r|dk rtd|dk r0|dk r0td|dk s@|dk rVddl} | dtd||_||_|dkr|tj|j||d}||_ d|_ t ||||||| dS)Nz4context and keyfile arguments are mutually exclusivez5context and certfile arguments are mutually exclusiverzAkeyfile and certfile are deprecated, use a custom context insteadrl)certfilekeyfileF) rCwarningswarnDeprecationWarningrrsslZ_create_stdlib_context ssl_versioncontext_prot_prr) rrrrrrrrrrrrrrrs"zFTP_TLS.__init__TcCs*|rt|jtjs|t||||S)N)rrr SSLSocketauthrr)rrrrZsecurerrrrsz FTP_TLS.logincCsft|jtjrtd|jtjkr.|d}n |d}|jj |j|j d|_|jj d|j d|_ |S)NzAlready using TLSzAUTH TLSzAUTH SSL)server_hostnamer%)moder&)rrrrrCrZ PROTOCOL_TLSrdr wrap_socketrr+r&r,)rrYrrrrs     z FTP_TLS.authcCs0t|jtjstd|d}|j|_|S)Nz not using TLSZCCC)rrrrrCrdr)rrYrrrcccs   z FTP_TLS.ccccCs|d|d}d|_|S)NzPBSZ 0zPROT PT)rdr)rrYrrrprot_p s  zFTP_TLS.prot_pcCs|d}d|_|S)NzPROT CF)rdr)rrYrrrprot_cs zFTP_TLS.prot_ccCs2t|||\}}|jr*|jj||jd}||fS)N)r)rrrrrr)rrbr|r~r}rrrr$s  zFTP_TLS.ntransfercmdcCs8dt}|j||}|dddkr4t||S)NsABORrO>r\r]r^)r_rrErSr)rrGrYrrrra+s  z FTP_TLS.abort)rrrT)N)r r rrZPROTOCOL_TLS_CLIENTrrrrrrrrrrarrrrrs!    rcCs\|dddkrt|tdkrt |d}||fS) NrOZ227rz#(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)rerPr8) r_227_rerrrsearchrgroupsrir)rYrrZnumbersrr'rrrrvNs rvcCs|dddkrt||d}|dkr2t||d|d}|dkrRt|||d||dkrrt|||d|||d}t|dkrt||d}t|d}||fS)NrOZ229(r)r r8)rfindrrhr<r)rYZpeerleftrightpartsrr'rrrrxbs    rxcCs|dddkrt||dddkr,dSd}d}t|}xJ||kr||}|d}|dkr|||ksr||dkrtP|d}||}q>W|S)NrOrr8z "rr ")rr<)rYrr@nrZrrrrxs   rcCs t|dS)N)r0)rGrrrrsrrIc Cs|s|}d|}||||t|d\}}||||d|}|dddkrdt|d|}|dddkrt||dS)NzTYPE ruzSTOR rO>125rzzRETR )rdrvrcrkrr[) sourceZ sourcenametargetZ targetnamerZ sourcehostZ sourceportZtreplyZsreplyrrrftpcps   rc Csttjdkr"ttjtdddl}d}d}x"tjddkrT|d}tjd=q4Wtjddddkrtjddd}tjd=tjd}t|}| |d}}}y||}Wn(t k r|dk rtj dYn:Xy| |\}}}Wn"tk rtj dYnX||||xtjddD]} | ddd krf|| ddnt| dddkrd } | ddr| d | dd} || } n0| d kr||j n|d | tjj dq'sN   k  |  9