
    RSi0                     &   d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZ 	 ddl
mZ n# e$ r dZY nw xY wdZ G d dej                  Zd Zd Zd Zd ZddZddZedk    r e             dS dS )zX
Start a standalone anonymous FTP server from the command line:

$ python3 -m pyftpdlib
    N   )servers)DummyAuthorizer)
FTPHandler)config_logging)	cpu_count)hilite)term_supports_colors)TLS_FTPHandleriI  c                   $     e Zd Z fdZd Z xZS )ColorHelpFormatterc                     t          |                                d           }t                                          |           d S )Norange)r	   
capitalizesuperstart_section)selfheading	__class__s     F/home/jrussi/.local/lib/python3.11/site-packages/pyftpdlib/__main__.pyr   z ColorHelpFormatter.start_section#   s?    G..00(;;=g&&&&&    c                    |j         s; |                     ||j                  d          d         }t          |d           S g }|j         D ]&}|                    t          |d                      '|j        dk    rK|                     ||                     |                    }|dxx         dt          |d           z   z  cc<   d                    |          S )	Nr   r   white	lightblue green, )	option_strings_metavar_formatterdestr	   appendnargs_format_args!_get_default_metavar_for_optionaljoin)r   actiondefaultpartsoptionmetavars         r   _format_action_invocationz,ColorHelpFormatter._format_action_invocation'   s    $ 	1Bd--ffkBB1EEaHGWg..00+ 	; 	;FLLF6;779::::<1''>>vFF G "III&'":":<<<IIIyyr   )__name__
__module____qualname__r   r,   __classcell__)r   s   @r   r   r   "   sG        ' ' ' ' '             r   r   c                 ~    	 t          j        |            n&# t          $ r t          j        d|           d w xY w| S )Nzunknown encoding: )codecslookupLookupErrorargparseArgumentTypeErrorvalues    r   parse_encodingr9   :   s_    e   (***
 
	 Ls    #:c                    	 |                      d          \  }}t          |          t          |          }}n'# t          $ r t          j        d| d          d w xY wd|cxk    rdk    rn nd|cxk    rdk    sn t          j        d          ||k    rt          j        d| d| d          t          t          ||dz                       S )	N-zinvalid port range: z (expected FROM-TO)r   i  z(port numbers must be between 1 and 65535z%start port must be <= stop port (got ))splitint
ValueErrorr5   r6   listrange)r8   startstops      r   parse_port_rangerD   D   s"   kk#&&t%jj#d))t   (?5???
 
	 %A$6$6$6$6$6$6$6$6(6
 
 	
 }}(CECCDCCC
 
 	
 eTAX&&'''s	   69 $Ac           	         t           j        dft           j        dfd}t          t           d          rt           j        df|d<   t
          j        dk    rEt           j        t                      f|d<   t                      dk    rt          j	        dd	           | |vr7t          j        d
| dd                    d |D                                  ||          \  }}||fS )Nr   )asynczmulti-threadMultiprocessFTPServerz
multi-procposixzpre-forkz9ignoring 'pre-fork' concurrency model: there's only 1 CPU   )
stacklevelzinvalid concurrency z; choose between: r   c                 ,    g | ]}t          |          S  )repr).0xs     r   
<listcomp>z%parse_concurrency.<locals>.<listcomp>k   s    333a$q''333r   )r   	FTPServerThreadedFTPServerhasattrrG   osnamer   warningswarnr5   r6   r&   )r8   mappingserver_classncpuss       r   parse_concurrencyr[   W   s   #Q' 2A6 G
 w/00 C!(!> B	w'&0)++>
;;!MK   
 G(75 7 7yy337333447 7
 
 	

 "%.L%%  r   c                 t    t           j                            |           st          j        d| d          | S )Nzfile z does not exist)rT   pathisfiler5   r6   r7   s    r   parse_file_pathr_   r   s;    7>>%   K()I)I)I)IJJJLr   c           
      F   d}t          j        |t          j        t	                      rt
          nt           j                  }|                    d          }|                    ddd dd           |                    d	d
t          t          ddt           d           |                    ddddd           |                    ddt          j                    dd           |                    ddd dd           |                    ddt          d dd           |                    d d!dd"#           |                    d$d%t          d d&'           |                    d(d)t          d d*'           |                    d+t          d,d-'           |                    d.          }|                    d/ddd01           |                    d2t           dd34           |                    d5t           dd64           |                    d7ddd81           |                    d9ddd:1           |                    d;          }|                    d<t          d=t"          j        d>t"          j         d?@           |                    dAt          t"          j        dBt"          j        d'           |                    dCt"          j        ddD1           |                    dEt"          j        ddF1           |                    dGt,          dHdIt"          j         d'           |                    dJdddK1           t1          t          dL          r|                    dMdddN1           |                    dOt          t2          j        j        dPt2          j        j         d'           |                    dQt          t2          j        j        dR'           |                    dSt          t"          j        dTt"          j         d'           |                    |           S )UNzpython3 -m pyftpdlib [options])usagedescriptionformatter_classzMain optionsz-iz--interfaceADDRESSz9specify the interface to run on (default: all interfaces))r(   r+   helpz-pz--portPORTz(specify port number to run on (default: r<   )typer(   r+   re   z-wz--write
store_trueFz;grants write access for logged in user (default: read-only))r'   r(   re   z-dz--directoryPATHz;specify the directory to share (default: current directory)z-nz--nat-addressz.the NAT address to use for passive connectionsz-rz--rangezFROM-TOzIthe range of TCP ports to use for passive connections (e.g. -r 8000-9000)z-Dz--debugzenable DEBUG logging level)r'   re   z-uz
--usernamezcspecify username to login with (anonymous login will be disabled and password required if supplied))rg   r(   re   z-Pz
--passwordzAspecify a password to login with (username required to be useful)z--concurrencyrF   zmthe FTP server concurrency model to use, either 'async' (default), 'pre-fork', 'multi-thread' or 'multi-proc'zTLS optionsz--tlszMwhether to enable FTPS (FTP over TLS); requires --keyfile and --certfile args)r(   r'   re   z	--keyfilezthe TLS key file)rg   r+   re   z
--certfilezthe TLS certificate filez--tls-control-requiredz4impose TLS for the control connection (before login)z--tls-data-requiredz"impose TLS for the data connectionzOther optionsz	--timeoutSECONDSzconnection timeout (default: z	 seconds))rg   r+   r(   re   z--bannerz0the message sent when client connects (default: z--permit-foreign-addresseszOallow data connections from an IP address different than the control connectionz--permit-privileged-portsz7allow data connections (PORT) over privileged TCP portsz
--encodingzutf-8z>the encoding used for client / server communication (default: z--use-localtimezSdisplay directory listings with the time in your local time zone (default: use GMT)sendfilez--disable-sendfilez:disable sendfile() syscall, used for faster file transfersz
--max-consz1max number of simultaneous connections (default: z--max-cons-per-ipzHmaximum number connections from the same IP address (default: unlimited)z--max-login-attemptszAmax number of failed authentications before disconnect (default: )r5   ArgumentParsermain__doc__r
   r   HelpFormatteradd_argument_groupadd_argumentr>   DEFAULT_PORTrT   getcwdrD   strr[   r_   r   timeoutbannerpermit_foreign_addressespermit_privileged_portsr9   encodingrS   r   rQ   max_consmax_login_attempts
parse_args)argsra   parser
group_main	group_tls
group_miscs         r   r|   r|   x   s   ,E$L $%%('  F **>::JH     GGGG     J     	J     =     .  
 
 
 )	       
 
 
 O     E     ))-88I     	     '	      C	     1	     **?;;J"JZ-?JJJ     !'!' ' '     $3"     #2F	     '#' ' '     "     r: 
 M	 	  	
 	
 	
 !*.!*. . .     !*     -1-1 1 1     T"""r   c                 p   t          |           }|j        rt          t          j                   t
          j        dv r|j        sd|_        t                      }|j	        rdnd}|j
        rD|j        st          j        d          |                    |j
        |j        |j        |           n|                    |j        |           |j        ryt$          t          j        d
          |j        r|j        st          j        d          t$          }|j        |_        |j        |_        |j        rd|_        |j        rd|_        n)|j        s|j        rt          j        d          t.          }||_        |j        |_        |j        |_        |j        |_        |j        |j        _        |j        |_        |j         |_         |j!        |_!        |j"        |_"        |j#        |_#        |j$         |_%        tM          t
          d          r|j'         |_(        |j)        \  }} ||j        |j*        f|          }|j+        |_+        |j,        |_,        t
          j        dk    rdnd	}	 |-                    ||           |.                                 n# |.                                 w xY w| r|S d	S )z(Start a standalone anonymous FTP server.)r}   )level)ntcez0.0.0.0
elradfmwMTelrz7if username (-u) is supplied, password (-P) is required)permNzPyOpenSSL not installedz,--tls requires --keyfile and --certfile argsTz0--keyfile and --certfile args requires --tls argrk   r   rI   )ru   worker_processes)/r|   debugr   loggingDEBUGrT   rU   	interfacer   writeusernamepasswordr5   r6   add_user	directoryadd_anonymoustlsr   certfilekeyfiletls_control_requiredtls_data_requiredr   
authorizernat_addressmasquerade_addressrA   passive_portsru   dtp_handlerrv   r{   rw   rx   ry   use_localtimeuse_gmt_timesrS   disable_sendfileuse_sendfileconcurrencyportrz   max_cons_per_ipserve_forever	close_all)	r}   optsr   r   handlerrY   rZ   serverru   s	            r   rm   rm   Y  s   4   Dz ,W]++++
 
w,t~" ""J:0<<5D} 	<} 	,I   	M4=$.t 	 	
 	
 	
 	
 	  d ;;; x !,-FGGG} 	DL 	,>   !=,$ 	0+/G(! 	-(,G%= 	DL 	,B    $G!%!1G JGlGO"&,G[GN!%!8G'+'DG$&*&BG#}G $ 22Gr: 9#'#88 *L%\4>495w??FmFO!1F 7d??aaGWuEEE  s   -J J/__main__)N)rn   r5   r2   r   rT   rV    r   authorizersr   handlersr   logr   preforkr   utilsr	   r
   r   ImportErrorrr   ro   r   r9   rD   r[   r_   r|   rm   r-   rL   r   r   <module>r      s  
     				        ( ( ( ( ( (                               ' ' ' ' ' '(((((((   NNN          /      0  ( ( (&! ! !6  ^# ^# ^# ^#BO O O Od zDFFFFF s   A	 	AA