AlkantarClanX12

Your IP : 3.148.108.201


Current Path : /opt/alt/python312/lib64/python3.12/__pycache__/
Upload File :
Current File : //opt/alt/python312/lib64/python3.12/__pycache__/ftplib.cpython-312.pyc

�

�Q�f�����dZddlZddlZddlmZgd�ZdZdZdZGd�d	e�Z	Gd
�de	�Z
Gd�d
e	�ZGd�de	�ZGd�de	�Z
e	eefZdZdZGd�d�Z	ddlZej*ZGd�de�Zej1d�e	eeej2fZdad�Zdad�Zd�Zd�Z d�Z!d d�Z"d�Z#e$dk(re#�yy#e$rdZY�1wxYw)!aSAn FTP client class and some helper functions.

Based on RFC 959: File Transfer Protocol (FTP), by J. Postel and J. Reynolds

Example:

>>> from ftplib import FTP
>>> ftp = FTP('ftp.python.org') # connect to host, default port
>>> ftp.login() # default, i.e.: user anonymous, passwd anonymous@
'230 Guest login ok, access restrictions apply.'
>>> ftp.retrlines('LIST') # list directory contents
total 9
drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 .
drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 ..
drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 bin
drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 etc
d-wxrwxr-x   2 ftp      wheel        1024 Sep  5 13:43 incoming
drwxr-xr-x   2 root     wheel        1024 Nov 17  1993 lib
drwxr-xr-x   6 1094     wheel        1024 Sep 13 19:07 pub
drwxr-xr-x   3 root     wheel        1024 Jan  3  1994 usr
-rw-r--r--   1 root     root          312 Aug  1  1994 welcome.msg
'226 Transfer complete.'
>>> ftp.quit()
'221 Goodbye.'
>>>

A nice test that reveals some of the network dialogue would be:
python ftplib.py -d localhost -l -p -l
�N)�_GLOBAL_DEFAULT_TIMEOUT)�FTP�error_reply�
error_temp�
error_perm�error_proto�
all_errors��� c��eZdZy)�ErrorN��__name__�
__module__�__qualname__���-/opt/alt/python312/lib64/python3.12/ftplib.pyrr9��rrc��eZdZy)rNrrrrrr:rrrc��eZdZy)rNrrrrrr;rrrc��eZdZy)rNrrrrrr<rrrc��eZdZy)rNrrrrrr=rrr�
s
c�X�eZdZdZdZdZeZeZ	dZ
dZdZdZ
dZddddedfdd�d	�Zd
�Zd�Zd2d�Zd
�Zd�ZeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d3d�Z&d3d�Z'd4d �Z(d5d!�Z)d3d"�Z*d6d#�Z+d3d$�Z,d%�Z-d&�Z.d'�Z/dgfd(�Z0d)�Z1d*�Z2d+�Z3d,�Z4d-�Z5d.�Z6d/�Z7d0�Z8d1�Z9y)7ru�An FTP client class.

    To create a connection, call the class using these arguments:
            host, user, passwd, acct, timeout, source_address, encoding

    The first four arguments are all strings, and have default value ''.
    The parameter ´timeout´ must be numeric and defaults to None if not
    passed, meaning that no timeout will be set on any ftp socket(s).
    If a timeout is passed, then this is now the default timeout for all ftp
    socket operations for this instance.
    The last parameter is the encoding of filenames, which defaults to utf-8.

    Then use self.connect() with optional host and port argument.

    To download a file, use ftp.retrlines('RETR ' + filename),
    or ftp.retrbinary() with slightly different arguments.
    To upload a file, use ftp.storlines() or ftp.storbinary(),
    which have an open file as argument (see their definitions
    below for details).
    The download/upload functions first issue appropriate TYPE
    and PORT or PASV commands.
    r�NTF�utf-8��encodingc��||_||_||_|r(|j|�|r|j	|||�yyy)z�Initialization method (called by class instantiation).
        Initialize host to localhost, port to standard ftp port.
        Optional arguments are host (for connect()),
        and user, passwd, acct (for login()).
        N)r �source_address�timeout�connect�login)�self�host�user�passwd�acctr#r"r s        r�__init__zFTP.__init__msF��!��
�,��������L�L�����
�
�4���.��rc��|S�Nr�r&s r�	__enter__z
FTP.__enter__}s���rc���|j�/	|j�|j�|j	�yyy#ttf$rY�0wxYw#|j�|j	�wwxYwr-)�sock�quit�OSError�EOFError�close)r&�argss  r�__exit__zFTP.__exit__�sm���9�9� �
!��	�	���9�9�(��J�J�L�)�
!���X�&�
��
���9�9�(��J�J�L�)�s!�=�A�A�A�A�A1c�X�|dk7r||_|dkDr||_|dk7r||_|j�|jstd��|�||_tjd||j|j�tj|j|jf|j|j��|_	|jj|_|jjd|j��|_|j�|_|j S)	awConnect to host.  Arguments are:
         - host: hostname to connect to (string, default previous host)
         - port: port to connect to (integer, default previous port)
         - timeout: the timeout to set against the ftp socket(s)
         - source_address: a 2-tuple (host, port) for the socket to bind
           to as its source address before connecting.
        rr����z0Non-blocking socket (timeout=0) is not supportedzftplib.connect�r"�rr)r'�portr#�
ValueErrorr"�sys�audit�socket�create_connectionr1�family�af�makefiler �file�getresp�welcome)r&r'r<r#r"s     rr$zFTP.connect�s����2�:��D�I��!�8��D�I��d�?�"�D�L��<�<�#�D�L�L��O�P�P��%�"0�D���	�	�"�D�$�)�)�T�Y�Y�?��,�,�d�i�i����-C�T�\�\�<@�<O�<O�Q��	��)�)�"�"����I�I�&�&�s�T�]�]�&�C��	��|�|�~����|�|�rc�|�|jr%td|j|j��|jS)z`Get the welcome message from the server.
        (this is read and squirreled away by connect())z	*welcome*)�	debugging�print�sanitizerGr.s r�
getwelcomezFTP.getwelcome�s,���>�>��+�t�}�}�T�\�\�:�;��|�|�rc��||_y)z�Set the debugging level.
        The required argument level means:
        0: no debugging output (default)
        1: print commands and responses but not body text etc.
        2: also print raw lines read and sent before stripping CR/LFN)rI)r&�levels  r�set_debuglevelzFTP.set_debuglevel�s����rc��||_y)z�Use passive or active mode for data transfers.
        With a false argument, use the normal PORT mode,
        With a true argument, use the PASV command.N)�
passiveserver)r&�vals  r�set_pasvzFTP.set_pasv�s��!��rc��|dddvr.t|jd��}|ddd|dz
zz||dz}t|�S)N�>�pass �PASS r�*)�len�rstrip�repr)r&�s�is   rrKzFTP.sanitize�sP���R�a�5�&�&��A�H�H�V�$�%�A��"�1���Q�q�S�	�!�A�a�b�E�)�A��A�w�rc�&�d|vsd|vrtd��tjd||�|tz}|jdkDrtd|j
|��|jj|j|j��y)N�
�
z4an illegal newline character should not be containedzftplib.sendcmdr
z*put*)r=r>r?�CRLFrIrJrKr1�sendall�encoder �r&�lines  r�putlinezFTP.putline�ss���4�<�4�4�<��S�T�T��	�	�"�D�$�/��d�{���>�>�A���'�4�=�=��.�/��	�	���$�+�+�d�m�m�4�5rc�t�|jrtd|j|��|j|�y)Nz*cmd*)rIrJrKrfrds  r�putcmdz
FTP.putcmd�s'���>�>�5��$�-�-��*=�>����T�rc�`�|jj|jdz�}t|�|jkDrt	d|jz��|j
dkDrt
d|j|��|st�|ddtk(r|dd}|S|ddtvr|dd}|S)Nr
�got more than %d bytesz*get*������)
rE�readline�maxlinerYrrIrJrKr4rards  r�getlinezFTP.getline�s����y�y�!�!�$�,�,��"2�3���t�9�t�|�|�#��0�4�<�<�?�@�@��>�>�A���'�4�=�=��.�/���N����9������9�D����"�#�Y�$�
����9�D��rc��|j�}|dddk(r2|dd}	|j�}|d|zz}|dd|k(r|dddk7r	|S�,|S)N���-r`)ro)r&re�code�nextlines    r�getmultilinezFTP.getmultiline�sr���|�|�~����!�9������8�D���<�<�>���t�h��/���B�Q�<�4�'� ��1�
��,����
��rc���|j�}|jrtd|j|��|dd|_|dd}|dvr|S|dk(rt|��|dk(rt
|��t|��)Nz*resp*rqr
>�1�2�3�4�5)rvrIrJrK�lastresprrr)r&�resp�cs   rrFzFTP.getresp�s~��� � �"���>�>��(�D�M�M�$�/�0��R�a���
���!�H������K���8��T�"�"���8��T�"�"��$��rc�L�|j�}|dddk7rt|��|S)z%Expect a response beginning with '2'.Nr
ry)rFr�r&r~s  r�voidrespzFTP.voidresps*���|�|�~�����8�s�?��d�#�#��rc���dtz}|jdkDrtd|j|��|jj|t�|j�}|dddvrt|��|S)z�Abort a file transfer.  Uses out-of-band data.
        This does not follow the procedure from the RFC to send Telnet
        IP and Synch; that doesn't seem to work with the servers I've
        tried.  Instead, just send the ABOR command as OOB data.�ABORr
z*put urgent*Nrq>�225�226�426)	�B_CRLFrIrJrKr1rb�MSG_OOBrvr�r&rer~s   r�abortz	FTP.abortsn��
�����>�>�A���.�$�-�-��"5�6��	�	���$��(�� � �"�����8�0�0��d�#�#��rc�D�|j|�|j�S)z'Send a command and return the response.)rhrF�r&�cmds  r�sendcmdzFTP.sendcmds�����C���|�|�~�rc�D�|j|�|j�S)z8Send a command and expect a response beginning with '2'.)rhr�r�s  r�voidcmdzFTP.voidcmds�����C���}�}��rc��|jd�}t|dz�t|dz�g}||z}ddj|�z}|j|�S)zUSend a PORT command with the current host and the given
        port number.
        �.�zPORT �,)�splitr[�joinr�)r&r'r<�hbytes�pbytes�bytesr�s       r�sendportzFTP.sendport sU�����C����t�S�y�/�4��S��>�2������������'���|�|�C� � rc��d}|jtjk(rd}|jtjk(rd}|dk(rt	d��dt|�|t|�dg}ddj
|�z}|j|�S)zESend an EPRT command with the current host and the given port number.rr
�zunsupported address familyrzEPRT �|)rCr@�AF_INET�AF_INET6rr[r�r�)r&r'r<rC�fieldsr�s      r�sendeprtzFTP.sendeprt*s~��
���7�7�f�n�n�$��B��7�7�f�o�o�%��B�
��7��:�;�;��d�2�h��d�4�j�"�5�������(�(���|�|�C� � rc��tjd|jd��}|j�d}|jj�d}|jtj
k(r|j
||�}n|j||�}|jtur|j|j�|S)z3Create a new socket and send a PORT command for it.)rrr
)rB�backlogr)r@�
create_serverrC�getsocknamer1r�r�r�r#r�
settimeout)r&r1r<r'r~s     r�makeportzFTP.makeport7s����#�#�G�D�G�G�Q�G�����!�!�$���y�y�$�$�&�q�)���7�7�f�n�n�$��=�=��t�,�D��=�=��t�,�D��<�<�6�6��O�O�D�L�L�)��rc�P�|jtjk(rPt|j	d��\}}|j
r|}||fS|jj�d}||fSt|j	d�|jj��\}}||fS)z<Internal: Does the PASV or EPSV handshake -> (address, port)�PASVr�EPSV)	rCr@r��parse227r��trust_server_pasv_ipv4_addressr1�getpeername�parse229)r&�untrusted_hostr<r's    r�makepasvzFTP.makepasvDs����7�7�f�n�n�$�#+�D�L�L��,@�#A� �N�D��2�2�%��
�T�z���y�y�,�,�.�q�1���T�z��"�$�,�,�v�"6��	�	�8M�8M�8O�P�J�D�$��T�z�rc��d}|jr�|j�\}}tj||f|j|j
��}	|�|j
d|z�|j
|�}|ddk(r|j�}|ddk7rt|��n�|j�5}|�|j
d|z�|j
|�}|ddk(r|j�}|ddk7rt|��|j�\}}	|jtur|j|j�ddd�dddk(rt|�}|fS#|j��xYw#1swY�6xYw)	a�Initiate a transfer over the data connection.

        If the transfer is active, send a port command and the
        transfer command, and accept the connection.  If the server is
        passive, send a pasv command, connect to it, and start the
        transfer command.  Either way, return the socket for the
        connection and the expected size of the transfer.  The
        expected size may be None if it could not be determined.

        Optional `rest' argument can be a string that is sent as the
        argument to a REST command.  This is essentially a server
        marker used to tell the server to skip over any data up to the
        given marker.
        Nr:zREST %srryrxrq�150)rQr�r@rAr#r"r�rFrr5r��acceptrr��parse150)
r&r��rest�sizer'r<�connr~r1�sockaddrs
          r�ntransfercmdzFTP.ntransfercmdPso�����������J�D�$��+�+�T�4�L�$�,�,�;?�;N�;N�P�D�
��#��L�L��T�!1�2��|�|�C�(����7�c�>��<�<�>�D���7�c�>�%�d�+�+�"�����D��#��L�L��T�!1�2��|�|�C�(����7�c�>��<�<�>�D���7�c�>�%�d�+�+�!%������h��<�<�'>�>��O�O�D�L�L�1�!����8�u���D�>�D��T�z���'
��
�
���� ��s�AE&�4BE<�&E9�<Fc�,�|j||�dS)z0Like ntransfercmd() but returns only the socket.r)r�)r&r�r�s   r�transfercmdzFTP.transfercmd�s��� � ��d�+�A�.�.rc��|sd}|sd}|sd}|dk(r	|dvr|dz}|jd|z�}|ddk(r|jd|z�}|ddk(r|jd	|z�}|dd
k7rt|��|S)zLogin, default anonymous.�	anonymousr>rrsz
anonymous@zUSER rrzrW�ACCT ry�r�r)r&r(r)r*r~s     rr%z	FTP.login�s�����D���F���D��;��6�Y�#6��l�*�F��|�|�G�d�N�+����7�c�>��<�<��&� 0�1�D���7�c�>��<�<��$��/�D���7�c�>��d�#�#��rc�Z�|jd�|j||�5}|j|�x}r||�|j|�x}r�t� t	|t�r|j�ddd�|j
�S#1swY|j
�SxYw)a�Retrieve data in binary mode.  A new port is created for you.

        Args:
          cmd: A RETR command.
          callback: A single parameter callable to be called on each
                    block of data read.
          blocksize: The maximum number of bytes to read from the
                     socket at one time.  [default: 8192]
          rest: Passed to transfercmd().  [default: None]

        Returns:
          The response code.
        �TYPE IN)r�r��recv�
_SSLSocket�
isinstance�unwrapr�)r&r��callback�	blocksizer�r��datas       r�
retrbinaryzFTP.retrbinary�s���	
���X��
�
�
�c�4�
(�D��)�)�I�.�.�$�.�����)�)�I�.�.�$�.��%�*�T�:�*F����
�)��}�}���
)��}�}���s�/B�&B�B*c��|�t}|jd�}|j|�5}|jd|j��5}	|j|jdz�}t|�|jkDrtd|jz��|jdkDrtdt|��|sn(|d	dtk(r|dd	}n
|d
ddk(r|dd
}||���t� t|t�r|j�ddd�ddd�|j!�S#1swY�!xYw#1swY|j!�SxYw)ahRetrieve data in line mode.  A new port is created for you.

        Args:
          cmd: A RETR, LIST, or NLST command.
          callback: An optional single parameter callable that is called
                    for each line with the trailing CRLF stripped.
                    [default: print_line()]

        Returns:
          The response code.
        N�TYPE Ar;rr
rjr�z*retr*rkrlr`)�
print_liner�r�rDr rmrnrYrrIrJr[rar�r�r�r�)r&r�r�r~r��fpres       r�	retrlinesz
FTP.retrlines�s/����!�H��|�|�H�%��
�
�
�c�
"�d����s�T�]�]��;�r���{�{�4�<�<�!�#3�4���t�9�t�|�|�+�� 8�4�<�<� G�H�H��>�>�A�%��(�D��J�/������9��$����9�D��"�#�Y�$�&����9�D������%�*�T�:�*F����
�!<�#�$�}�}���#<�;��#�$�}�}���s$�D:�	CD.�D:�.D7	�3D:�:Ec��|jd�|j||�5}|j|�x}r/|j|�|r||�|j|�x}r�/t� t|t�r|j
�ddd�|j�S#1swY|j�SxYw)a9Store a file in binary mode.  A new port is created for you.

        Args:
          cmd: A STOR command.
          fp: A file-like object with a read(num_bytes) method.
          blocksize: The maximum data size to read from fp and send over
                     the connection at once.  [default: 8192]
          callback: An optional single parameter callable that is called on
                    each block of data after it is sent.  [default: None]
          rest: Passed to transfercmd().  [default: None]

        Returns:
          The response code.
        r�N)r�r��readrbr�r�r�r�)r&r�r�r�r�r�r��bufs        r�
storbinaryzFTP.storbinary�s���	
���X��
�
�
�c�4�
(�D�����+�+�#�+����S�!���S�M�����+�+�#�+�
�%�*�T�:�*F����
�)��}�}���)��}�}���s�AB%�'&B%�%B=c� �|jd�|j|�5}	|j|jdz�}t	|�|jkDrtd|jz��|snA|ddtk7r|dtvr|dd}|tz}|j|�|r||���t� t|t�r|j�ddd�|j�S#1swY|j�SxYw)ahStore a file in line mode.  A new port is created for you.

        Args:
          cmd: A STOR command.
          fp: A file-like object with a readline() method.
          callback: An optional single parameter callable that is called on
                    each line after it is sent.  [default: None]

        Returns:
          The response code.
        r�r
rjrkNrl)r�r�rmrnrYrr�rbr�r�r�r�)r&r�r�r�r�r�s      r�	storlinesz
FTP.storlines�s���	
���X��
�
�
�c�
"�d���k�k�$�,�,��"2�3���s�8�d�l�l�*�� 8�4�<�<� G�H�H����r�s�8�v�%��2�w�&�(��C�R��#���,�C����S�!���S�M���%�*�T�:�*F����
�#� �}�}���!#� �}�}���s�B:C5�5D
c�.�d|z}|j|�S)zSend new account name.r��r�)r&�passwordr�s   rr*zFTP.accts���� ���|�|�C� � rc�d�d}|D]
}|d|zz}�g}|j||j�|S)zBReturn a list of files in a given directory (default the current).�NLST� )r��append)r&r6r��arg�filess     r�nlstzFTP.nlsts;�����C���s��#�C�������s�E�L�L�)��rc��d}d}|ddrt|dt�s
|dd|d}}|D]
}|s�|d|zz}�|j||�y)aList a directory in long form.
        By default list current directory to stdout.
        Optional last argument is callback function; all
        non-empty arguments before it are concatenated to the
        LIST command.  (This *should* only be used for a pathname.)�LISTNrlr�)r��strr�)r&r6r��funcr�s     r�dirzFTP.dir&sb���������9�Z��R��#�6��c�r��D��H�$�D��C���S�3�Y�'���	
���s�D�!rc#�K�|r&|jddj|�zdz�|rd|z}nd}g}|j||j�|D]s}|j	t
�j
d�\}}}i}	|ddjd�D]*}
|
j
d�\}}}||	|j�<�,||	f���uy�w)	a<List a directory in a standardized format by using MLSD
        command (RFC-3659). If path is omitted the current directory
        is assumed. "facts" is a list of strings representing the type
        of information desired (e.g. ["type", "size", "perm"]).

        Return a generator object yielding a tuple of two elements
        for every file found in path.
        First element is the file name, the second one is a dictionary
        including a variable number of "facts" depending on the server
        and whether "facts" argument has been provided.
        z
OPTS MLST �;zMLSD %s�MLSDr�Nrl�=)	r�r�r�r�rZra�	partitionr��lower)
r&�path�factsr��linesre�facts_found�_�name�entry�fact�key�values
             r�mlsdzFTP.mlsd5s�������L�L�������7�#�=�>���d�"�C��C������s�E�L�L�)��D�#'�;�;�t�#4�#>�#>�s�#C� �K��D��E�#�C�R�(�.�.�s�3�� $���s� 3�
��Q��%*��c�i�i�k�"�4���-��
�s�C
Cc�x�|jd|z�}|ddk7rt|��|jd|z�S)zRename a file.zRNFR rrzzRNTO )r�rr�)r&�fromname�tonamer~s    r�renamez
FTP.renameQs?���|�|�G�h�.�/����7�c�>��d�#�#��|�|�G�f�,�-�-rc�R�|jd|z�}|dddvr|St|��)zDelete a file.zDELE Nrq>�200�250r�)r&�filenamer~s   r�deletez
FTP.deleteXs3���|�|�G�h�.�/�����8�~�%��K��d�#�#rc���|dk(r	|jd�S|dk(rd}d	|z}|j|�S#t$r }|jddddk7r�Yd}~�:d}~wwxYw)
zChange to a directory.z..�CDUPrNrq�500rr�zCWD )r�rr6)r&�dirname�msgr�s    r�cwdzFTP.cwd`st���d�?�
��|�|�F�+�+���]��G��w����|�|�C� � ��
�
��8�8�A�;�r��?�e�+��,��
�s�5�	A�A�Ac�x�|jd|z�}|dddk(r|ddj�}t|�Sy)zRetrieve the size of a file.zSIZE Nrq�213)r��strip�int)r&r�r~r\s    rr�zFTP.sizemsE���|�|�G�h�.�/�����8�u���Q�R���� �A��q�6�M�rc�d�|jd|z�}|jd�syt|�S)z+Make a directory, return its full pathname.zMKD �257r�r��
startswith�parse257)r&rr~s   r�mkdzFTP.mkdus0���|�|�F�W�,�-�����u�%����~�rc�*�|jd|z�S)zRemove a directory.zRMD r�)r&rs  r�rmdzFTP.rmd~s���|�|�F�W�,�-�-rc�^�|jd�}|jd�syt|�S)z!Return current working directory.�PWDr
rrr�s  r�pwdzFTP.pwd�s+���|�|�E�"�����u�%����~�rc�H�|jd�}|j�|S)zQuit, and close the connection.�QUIT)r�r5r�s  rr2zFTP.quit�s���|�|�F�#���
�
���rc���	|j}d|_|�|j�|j}d|_|�|j�yy#|j}d|_|�|j�wwxYw)z8Close the connection without assuming anything about it.N)rEr5r1)r&rEr1s   rr5z	FTP.close�sr��		��9�9�D��D�I����
�
���9�9�D��D�I����
�
�� ���9�9�D��D�I����
�
�� �s�%A�(A6)rrr9Nr-)rrr)rN)rNN):rrr�__doc__rIr'�FTP_PORTr<�MAXLINErnr1rErGrQr�rr+r/r7r$rLrO�debugrSrKrfrhrorvrFr�r�r�r�r�r�r�r�r�r�r%r�r�r�r�r*r�r�r�r�r�rr�rrrr2r5rrrrrJs*���.�I�
�D��D��G��D��D��G��M�%*�"��R���0��/�!�/� �!��4��
�E�!��6���$
� ����
�
!�!��
�5�n/��4�.!�F�4�>!�
�
"��"� �8.�$�!���.���rrc�f��eZdZdZd
deddd��fd�Zd�fd�	Zd�Zd�Zd	�Z	d
�Z
d�fd�	Zd�Z�xZ
S)�FTP_TLSa�A FTP subclass which adds TLS support to FTP as described
        in RFC-4217.

        Connect as usual to port 21 implicitly securing the FTP control
        connection before authenticating.

        Securing the data connection requires user to explicitly ask
        for it by calling prot_p() method.

        Usage example:
        >>> from ftplib import FTP_TLS
        >>> ftps = FTP_TLS('ftp.python.org')
        >>> ftps.login()  # login anonymously previously securing control channel
        '230 Guest login ok, access restrictions apply.'
        >>> ftps.prot_p()  # switch to secure data connection
        '200 Protection level set to P'
        >>> ftps.retrlines('LIST')  # list directory content securely
        total 9
        drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 .
        drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 ..
        drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 bin
        drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 etc
        d-wxrwxr-x   2 ftp      wheel        1024 Sep  5 13:43 incoming
        drwxr-xr-x   2 root     wheel        1024 Nov 17  1993 lib
        drwxr-xr-x   6 1094     wheel        1024 Sep 13 19:07 pub
        drwxr-xr-x   3 root     wheel        1024 Jan  3  1994 usr
        -rw-r--r--   1 root     root          312 Aug  1  1994 welcome.msg
        '226 Transfer complete.'
        >>> ftps.quit()
        '221 Goodbye.'
        >>>
        Nr)�contextr#r"r c	�z��|�tj�}||_d|_t�	|�|||||||��y)NFr)�ssl�_create_stdlib_contextr�_prot_p�superr+)
r&r'r(r)r*rr#r"r �	__class__s
         �rr+zFTP_TLS.__init__�sH������4�4�6��"�D�L� �D�L��G��T�4���$�n�x�
�
Irc���|r4t|jtj�s|j	�t
�|�|||�Sr-)r�r1r�	SSLSocket�authr"r%)r&r(r)r*�securer#s     �rr%z
FTP_TLS.login�s3����j����C�M�M�B��	�	���7�=��v�t�4�4rc��t|jtj�rt	d��|j
jtjk\r|jd�}n|jd�}|j
j|j|j��|_|jjd|j��|_
|S)z2Set up secure control connection by using TLS/SSL.zAlready using TLSzAUTH TLSzAUTH SSL��server_hostnamer;)�moder )r�r1rr%r=r�protocol�PROTOCOL_TLSr��wrap_socketr'rDr rEr�s  rr&zFTP_TLS.auth�s����$�)�)�S�]�]�3� �!4�5�5��|�|�$�$��(8�(8�8��|�|�J�/���|�|�J�/�����0�0����D�I�I�0�V�D�I��	�	�*�*��d�m�m�*�L�D�I��Krc���t|jtj�st	d��|jd�}|jj
�|_|S)z/Switch back to a clear-text control connection.z
not using TLS�CCC)r�r1rr%r=r�r�r�s  r�ccczFTP_TLS.ccc�sF���d�i�i����7� ��1�1��<�<��&�D��	�	�(�(�*�D�I��Krc�X�|jd�|jd�}d|_|S)zSet up secure data connection.zPBSZ 0zPROT PT�r�r!r�s  r�prot_pzFTP_TLS.prot_p�s*��
�L�L��"��<�<��)�D��D�L��Krc�6�|jd�}d|_|S)z"Set up clear text data connection.zPROT CFr3r�s  r�prot_czFTP_TLS.prot_c�s���<�<��)�D� �D�L��Krc���t�|�||�\}}|jr'|jj	||j
��}||fS)Nr))r"r�r!rr.r')r&r�r�r�r�r#s     �rr�zFTP_TLS.ntransfercmdsL�����-�c�4�8�J�D�$��|�|��|�|�/�/��@D�	�	�0�K����:�rc��dtz}|jj|�|j�}|dddvrt	|��|S)Nr�rq>r�r�r�)r�r1rbrvrr�s   rr�z
FTP_TLS.abort	sK���V�#�D��I�I���d�#��$�$�&�D��B�Q�x�4�4�!�$�'�'��Kr)rrrr)rrrTr-)rrrrrr+r%r&r1r4r6r�r��
__classcell__)r#s@rrr�sC���	�B	I� $�.E�$(�7�	I�	5�

	�	�	� 	�	�	rrc���|dddk7rt|��t�-ddl}|jd|j|j
z�atj
|�}|syt|jd��S)z�Parse the '150' response for a RETR request.
    Returns the expected transfer size or None; size is not guaranteed to
    be present in the 150 message.
    Nrqr�rz150 .* \((\d+) bytes\)r
)	r�_150_re�re�compile�
IGNORECASE�ASCII�matchr�group)r~r<�ms   rr�r�sl��
�B�Q�x�5���$�������*�*�%�r�}�}�r�x�x�'?�A���
�
�d��A����q�w�w�q�z�?�rc�H�|dddk7rt|��t� ddl}|jd|j�atj|�}|st
|��|j�}dj|dd�}t|d�dzt|d	�z}||fS)
z�Parse the '227' response for a PASV request.
    Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)'
    Return ('host.addr.as.numbers', port#) tuple.Nrq�227rz#(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)r�rr�rU)
r�_227_rer<r=r?�searchr�groupsr�r)r~r<rB�numbersr'r<s      rr�r�,s����B�Q�x�5���$�������*�*�C�R�X�X�N�����t��A���$����h�h�j�G��8�8�G�B�Q�K� �D����
�O�q� �C���
�O�3�D���:�rc��|dddk7rt|��|jd�}|dkrt|��|jd|dz�}|dkrt|��||dz||dz
k7rt|��||dz|j||dz�}t	|�dk7rt|��|d}t|d�}||fS)	z�Parse the '229' response for an EPSV request.
    Raises error_proto if it does not contain '(|||port|)'
    Return ('host.addr.as.numbers', port#) tuple.Nrq�229�(r�)r
rU)r�findrr�rYr)r~�peer�left�right�partsr'r<s       rr�r�?s����B�Q�x�5���$����9�9�S�>�D��a�x�{�4�(�(��I�I�c�4�!�8�$�E��q�y��$����D�1�H�~��e�a�i��(��$�������%� �&�&�t�D��F�|�4�E�
�5�z�Q���$�����7�D��u�Q�x�=�D���:�rc���|dddk7rt|��|dddk7ryd}d}t|�}||kr/||}|dz}|dk(r||k\s||dk7r	|S|dz}||z}||kr�/|S)	z�Parse the '257' response for a MKD or PWD request.
    This is a response to a MKD or PWD request: a directory name.
    Returns the directoryname in the 257 reply.Nrqr
rUz "rr
�")rrY)r~rr]�nrs     rr
r
Ts����B�Q�x�5���$����A�a�y�D����G�	�A��D�	�A�
�a�%���G��
�a�C����8��A�v��a��C����N��!��A��A�+���a�%��Nrc��t|�y)z+Default retrlines callback to print a line.N)rJ)res rr�r�js	��	�$�Krc�|�|s|}d|z}|j|�|j|�t|jd��\}}|j||�|jd|z�}|dddvrt�|jd|z�}|dddvrt�|j�|j�y)z+Copy file from one FTP-instance to another.zTYPE r�zSTOR Nrq>�125r��RETR )r�r�r�r�rr�)	�source�
sourcename�target�
targetname�type�
sourcehost�
sourceport�treply�sreplys	         r�ftpcprcos�����
��T�>�D�
�N�N�4��
�N�N�4��%�f�n�n�V�&<�=��J�
�
�O�O�J�
�+��^�^�G�j�0�
1�F�
�b�q�z��'���
�^�^�G�j�0�
1�F�
�b�q�z��'���
�O�O��
�O�O�rc�l�ttj�dkr.ttj
�tjd�ddl}d}d}tjddk(r-|dz}tjd=tjddk(r�-tjddddk(r'tjddd}tjd=tjd}t|�}|j|�dx}x}}	|j|�}	|j|�\}}}|j|||�tjddD]�}	|	dddk(r|j!|	dd�n�|	dddk(r$d}
|	ddr|
d
z|	ddz}
|j#|
�}n�|	dk(r|j%|j&�n`|j)d|	ztj*j,j.d�tj*j,j1�tj*j1���|j3�y#ttf$rtdtj�	�Y��RwxYw#t$r!|�td
tj�	�Y��wxYw)a�Test program.
    Usage: ftplib [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...

    Options:
      -d        increase debugging level
      -r[file]  set alternate ~/.netrc file

    Commands:
      -l[dir]   list directory
      -d[dir]   change the current directory
      -p        toggle passive and active mode
      file      retrieve the file and write it to stdout
    r�rNr
z-dz-rrz$No account -- using anonymous login.)rEz5Could not open account file -- using anonymous login.z-l�CWDr�z-prYi)rYr>�argvrJ�testr�exit�netrcrrO�authenticators�KeyError�	TypeError�stderrr3r%r�r�rSrQr��stdout�buffer�write�flushr2)rirI�rcfiler'�ftp�useridr)r*�netrcobjrEr�r~s            rrgrg�sR���3�8�8�}�q��
�d�l�l���������I�
�F�

�(�(�1�+��
��a�K�	��H�H�Q�K��(�(�1�+��
��x�x��{�2�A��$�����!��Q�R����H�H�Q�K��8�8�A�;�D�

�d�)�C����y�!���F��V�d�K��;�;�v�&��	K�#+�#:�#:�4�#@� �F�D�&��I�I�f�f�d�#�����������8�t���G�G�D���H��
�"�1�X��
��C��A�B�x�s�S�y�4���8�3���;�;�s�#�D�
�T�\��L�L�S�.�.�.�/��N�N�7�T�>��:�:�,�,�2�2�D�
:��J�J���#�#�%��
�
������H�H�J��%�)�$�	K��8�s�z�z�J�J�	K���#����I��z�z�
#��#�s$�J	�I�*J�J�	&J3�2J3�__main__)r�I)%rr>r@r�__all__r�rr�	Exceptionrrrrrr3r4r	rar�rrr%r�rr��SSLError�ImportErrorr;r�rFr�r�r
r�rcrgrrrr�<module>r|s!���L�
�*�������
���I���%���������%��
�W�h�
'�
���	��R	�R	�hu:�����J�k�#�k�Z�N�N�9����(�C�L�L�9�J����$���&�*�,�
�,=�@�z���F���K	���J��s�&C
�
C�C