%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/conch/ssh/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/conch/ssh/__pycache__/filetransfer.cpython-312.pyc

�

Ϫ�f”����ddlZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
ddlmZmZmZddlmZddlmZdd	lmZmZGd
�dej2�ZGd�d
e�ZGd�de�Zee	�Gd�d��ZGd�d�ZGd�de�Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*d Z+d!Z,d"Z-d#Z.d$Z/d%Z0d&Z1d'Z2d(Z3d)Z4d*Z5d+Z6d,Z7d-Z8d.Z9d/Z:d0Z;dZ<dZ=e=Z>dZ?dZ@d1ZAdZBdZCdZDdZEdZFdZGdZHdZIdZJd%ZKd2ZLd3ZMdZNdZOdZPdZQdZRdZSdZTdZUdZVd ZWeRZXeRZYeZ�Z[e\e[j���D]+Z^e^j�d4�s�e[e^Z`e^ddej�e`<�-[[[^[`y)5�N)�Dict)�implementer)�	ISFTPFile�ISFTPServer)�NS�getNS)�defer�error�protocol)�Logger)�failure)�nativeString�
networkStringc�h��eZdZUe�ZdZiZeee	fe
d<d�Zd�Zd�Z
d�Zd�Z�fd�Z�xZS)	�FileTransferBase)��packetTypesc� �d|_d|_y�N�)�buf�otherVersion��selfs �@/usr/lib/python3/dist-packages/twisted/conch/ssh/filetransfer.py�__init__zFileTransferBase.__init__s����� ��rc��|jjtjdt	|�dz|�|z�y)Nz!LB�)�	transport�write�struct�pack�len)r�kind�datas   r�
sendPacketzFileTransferBase.sendPacket"s.�������V�[�[���D�	�A�
�t�D�t�K�Lrc�2�|xj|z
c_t|j�dk\�r<|jdd}tjd|�\}}}t|j�d|zkry|jdd|z|jd|zdc}|_|jj|d�}|s|jjd|����t|d|��d�}|s=|jjd||dd�	�|j|td
|�����|jjd||��	||�t|j�dk\r��;yy#t$r!|jjd
|��Y��wxYw)N�	z!LBL��zno packet type for {kind})r$�packet_z+not implemented: {packetType} data={data!r})�
packetTyper%zdon't understand z+dispatching: {packetType} requestId={reqId})r,�reqIdz,Failed to handle packet of type {packetType})r,)
rr#r!�unpackr�get�_log�info�getattr�_sendStatus�FX_OP_UNSUPPORTED�	Exceptionr
)rr%�header�lengthr$r-r,�fs        r�dataReceivedzFileTransferBase.dataReceived%s������D����$�(�(�m�q� ��X�X�b�q�\�F�"(�-�-���"?��F�D�%��4�8�8�}�q�6�z�)��"�X�X�a�!�f�*�5�t�x�x��F�
��7M�N�D�$�(��)�)�-�-�d�D�9�J���	�	���:���F�����
�|�4�d�;�A���	�	���A�)��a�b����
� � ��,�0A�*��.N����I�I�N�N�=�%��
�
�

��$��W�$�(�(�m�q� ��X�
��	�	�!�!�B�)�"���
�s�E,�,&F�Fc���tjd|dd�\}i}|dd}|tztk(r%tjd|dd�\}||d<|dd}|tztk(r+tjd|dd�\}}||d<||d<|dd}|tztk(r%tjd|dd�\}||d	<|dd}|t
zt
k(r+tjd|dd�\}}	||d
<|	|d<|dd}|tztk(r]tjd|dd�\}
|dd}t|
�D]/}t|�\}}t|�\}
}|
|dt|���<�1||fS)
N�!Lr)�!Q��size�!2L�uid�gid�permissions�atime�mtime�ext_)
r!r.�FILEXFER_ATTR_SIZE�FILEXFER_ATTR_OWNERGROUP�FILEXFER_ATTR_PERMISSIONS�FILEXFER_ATTR_ACMODTIME�FILEXFER_ATTR_EXTENDED�rangerr)rr%�flags�attrsr>r@rA�permsrCrD�
extendedCount�i�extendedType�extendedDatas              r�_parseAttributesz!FileTransferBase._parseAttributes`s����=�=��t�B�Q�x�0������A�B�x���%�%�);�;��m�m�D�$�r��(�3�G�T� �E�&�M����8�D��+�+�/G�G��}�}�U�D��!�H�5�H�C���E�%�L��E�%�L����8�D��,�,�0I�I��}�}�T�4���8�4�H�U�#(�E�-� ����8�D��*�*�.E�E�!�=�=���R�a��9�L�E�5�"�E�'�N�"�E�'�N����8�D��)�)�-C�C�%�}�}�T�4���8�<��]����8�D��=�)�
J��',�T�{�$��t�',�T�{�$��t�=I���\�,�7�8�9�:�
J��d�{�rc���d}d}d|vr%|tjd|d�z
}|tz}d|vr-d|vr)|tjd|d|d�z
}|tz}d|vr%|tjd	|d�z
}|tz}d
|vr-d|vr)|tjd|d
|d�z
}|t
z}g}|D]M}|j
d�s�tt|d
d��}t||�}|j||z��O|r?|tjd	t|��z
}|dj|�z
}|tz}tjd	|�|zS)Nrrr>r<r@rAr?rBr;rCrDrEr))
r!r"rFrGrHrI�
startswithrr�appendr#�joinrJ)rrMrLr%�extended�k�extType�extDatas        r�_packAttributesz FileTransferBase._packAttributessy�������U�?��F�K�K��e�F�m�4�4�D��'�'�E��E�>�e�u�n��F�K�K��u�U�|�U�5�\�B�B�D��-�-�E��E�!��F�K�K��e�M�&:�;�;�D��.�.�E��e���5� 0��F�K�K��u�W�~�u�W�~�F�F�D��,�,�E����	3�A��|�|�F�#��]�1�Q�R�5�1�2���U�1�X�,������'� 1�2�		3�
��F�K�K��c�(�m�4�4�D��C�H�H�X�&�&�D��+�+�E��{�{�4��'�$�.�.rc�2��t�|�|�d|_y)zJ
        Called when connection to the remote subsystem was lost.
        FN)�super�connectionLost�	connected)r�reason�	__class__s  �rr_zFileTransferBase.connectionLost�s���
	���v�&���r)�__name__�
__module__�__qualname__rr0�versionsrr�int�str�__annotations__rr&r9rSr\r_�
__classcell__)rbs@rrrsF����8�D��H�"$�K��c�3�h��$�!�M�9�v�>/�6�rrc���eZdZd%d�Zd�Zd�Zd�Zd�Zd&d�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd'd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d �Z!d(d!�Z"d)d"�Z#d*d#�Z$d$�Z%y)+�FileTransferServerNc�j�tj|�t|�|_i|_i|_y�N)rrr�client�	openFiles�openDirs)rr%�avatars   rrzFileTransferServer.__init__�s*���!�!�$�'�!�&�)��������
rc���tjd|dd�\}tt|j�|gz�|_|dd}i}|r$t
|�\}}t
|�\}}|||<|r�$|jj||�}d}|j�D]\}}	|t|�t|	�zz
}�!|jttjd|j
�|z�y�Nr;r)r)r!r.�min�listrf�versionrro�
gotVersion�itemsrr&�FXP_VERSIONr")
rr%rw�ext�extNamer[�ourExt�
ourExtDatarY�vs
          r�packet_INITzFileTransferServer.packet_INIT�s����]�]�4��b�q��2�
���4��
�
�.�'��:�;����A�B�x�����!�$�K�M�G�T�!�$�K�M�G�T�"�C��L�����'�'���5���
��L�L�N�	(�D�A�q��"�Q�%�"�Q�%�-�'�J�	(�����V�[�[��t�|�|�%D�z�%Q�Rrc��|dd}|dd}t|�\}}tjd|dd�\}|dd}|j|�\}}|dk(s
Jd|����t	j
|jj|||�}|j|j|�|j|j|d�y)Nr)r;rzstill have data in OPEN: sopen failed)rr!r.rSr	�
maybeDeferredro�openFile�addCallback�_cbOpenFile�
addErrback�	_ebStatus)rr%�	requestId�filenamerLrM�ds       r�packet_OPENzFileTransferServer.packet_OPEN�s�����!�H�	��A�B�x���t����$��=�=��t�B�Q�x�0����A�B�x���+�+�D�1���t��s�{�@�7��x�@�@�{������� 4� 4�h��u�M��	�
�
�d�&�&�	�2�	���T�^�^�Y��?rc���ttt|���}||jvrt	d��||j|<|jt|t|�z�y)Nzid already open)rrh�hashrp�KeyErrorr&�
FXP_HANDLEr)r�fileObjr��fileIds    rr�zFileTransferServer._cbOpenFile�sR���s�4��=�1�2���T�^�^�#��,�-�-�!(����v�����
�I��6�
�$:�;rc��|dd}|dd}t|�\}}|jjd||��|dk(s
Jd|����||jvri|j|}t	j
|j�}|j|j||�|j|j|d�y||jvrm|j|d}t	j
|j�}|j|j||d�|j|j|d�ytj}tj|�}t!||�}	|jt#j$|	�|�y)	Nr)z!closing: {requestId!r} {handle!r})r��handlerzstill have data in CLOSE: sclose failedrr)rr0r1rpr	r��closer��_cbCloser�r�rq�errno�ENOENT�os�strerror�OSErrorr
�Failure)
rr%r�r�r�r��dirObj�code�text�errs
          r�packet_CLOSEzFileTransferServer.packet_CLOSE�sK����!�H�	��A�B�x���T�{�����	�	���/���	�	
�
�s�{�A�8���A�A�{��T�^�^�#��n�n�V�,�G��#�#�G�M�M�2�A�
�M�M�$�-�-���;�
�L�L�����O�D�
�t�}�}�
$��]�]�6�*�1�-�F��#�#�F�L�L�1�A�
�M�M�$�-�-���A�>�
�L�L�����O�D��<�<�D��;�;�t�$�D��$��%�C��N�N�7�?�?�3�/��;rc�l�|r|j|=n
|j|=|j|td�y)Nsfile closed)rqrpr3�FX_OK)r�resultr�r��isDirs     rr�zFileTransferServer._cbClose�s/����
�
�f�%����v�&�����E�>�:rc���|dd}|dd}t|�\}}tjd|dd�|ddc\}}}|dk(s
Jd|����||jvr.|j	tjt��|�y|j|}tj|j||�}|j|j|�|j|j|d�y)Nr)�!QL�rzstill have data in READ: sread failed)rr!r.rp�_ebReadr
r�r�r	r��	readChunkr��_cbReadr�r�)rr%r�r��offsetr7r�r�s        r�packet_READzFileTransferServer.packet_READ�s�����!�H�	��A�B�x���T�{����!'���u�d�3�B�i�!@�$�r�s�)�����$��s�{�@�7��x�@�@�{�����'��L�L������4�i�@��n�n�V�,�G��#�#�G�$5�$5�v�v�F�A�
�M�M�$�,�,�	�2�
�L�L�����N�Crc�f�|dk(r
t��|jt|t|�z�yr)�EOFErrorr&�FXP_DATAr�rr�r�s   rr�zFileTransferServer._cbRead�s(���S�=��*������)�b��j�"8�9rc��|dd}|dd}t|�\}}tjd|dd�\}|dd}t|�\}}|dk(s
Jd|����||jvr.|j	tjt��|�y|j|}tj|j||�}|j|j|d�|j|j|d�y)Nr)r<r=rzstill have data in WRITE: swrite succeededswrite failed)rr!r.rp�_ebWriter
r�r�r	r��
writeChunkr��	_cbStatusr�r�)rr%r�r�r��	writeDatar�r�s        r�packet_WRITEzFileTransferServer.packet_WRITEs�����!�H�	��A�B�x���T�{�����M�M�$��R�a��1�	���A�B�x����+��	�4��s�{�A�8���A�A�{�����'��M�M�'�/�/�(�*�5�y�A��n�n�V�,�G��#�#�G�$6�$6��	�J�A�
�M�M�$�.�.�)�5G�H�
�L�L�����O�Drc��|dd}|dd}t|�\}}|dk(s
Jd|����tj|jj|�}|j|j|d�|j|j|d�y)Nr)rzstill have data in REMOVE: sremove succeededs
remove failed)	rr	r�ro�
removeFiler�r�r�r�)rr%r�r�r�s     r�
packet_REMOVEz FileTransferServer.packet_REMOVEs�����!�H�	��A�B�x���t����$��s�{�B�9�$��B�B�{������� 6� 6��A��	�
�
�d�n�n�i�1D�E�	���T�^�^�Y�0@�Arc�8�|dd}|dd}t|�\}}t|�\}}|dk(s
Jd|����tj|jj||�}|j|j|d�|j|j|d�y)Nr)rzstill have data in RENAME: srename succeededs
rename failed)	rr	r�ro�
renameFiler�r�r�r�)rr%r��oldPath�newPathr�s      r�
packet_RENAMEz FileTransferServer.packet_RENAMEs�����!�H�	��A�B�x���d��
����d��
����s�{�B�9�$��B�B�{������� 6� 6���I��	�
�
�d�n�n�i�1D�E�	���T�^�^�Y�0@�Arc�D�|dd}|dd}t|�\}}|j|�\}}|dk(s
Jd|����tj|jj
||�}|j
|j|d�|j|j|d�y)Nr)rzstill have data in MKDIR: smkdir succeededsmkdir failed)
rrSr	r�ro�
makeDirectoryr�r�r�r��rr%r��pathrMr�s      r�packet_MKDIRzFileTransferServer.packet_MKDIR#s�����!�H�	��A�B�x���4�[�
��d��+�+�D�1���t��s�{�A�8���A�A�{������� 9� 9�4��G��	�
�
�d�n�n�i�1C�D�	���T�^�^�Y��@rc��|dd}|dd}t|�\}}|dk(s
Jd|����tj|jj|�}|j|j|d�|j|j|d�y)Nr)rzstill have data in RMDIR: srmdir succeededsrmdir failed)	rr	r�ro�removeDirectoryr�r�r�r��rr%r�r�r�s     r�packet_RMDIRzFileTransferServer.packet_RMDIR-s�����!�H�	��A�B�x���4�[�
��d��s�{�A�8���A�A�{������� ;� ;�T�B��	�
�
�d�n�n�i�1C�D�	���T�^�^�Y��@rc��|dd}|dd}t|�\}}|dk(s
Jd|����tj|jj|�}|j|j|�|j|j|d�y)Nr)rzstill have data in OPENDIR: sopendir failed)	rr	r�ro�
openDirectoryr��_cbOpenDirectoryr�r�r�s     r�packet_OPENDIRz!FileTransferServer.packet_OPENDIR6s�����!�H�	��A�B�x���4�[�
��d��s�{�C�:�4�(�C�C�{������� 9� 9�4�@��	�
�
�d�+�+�Y�7�	���T�^�^�Y�0A�Brc���ttt|���}||jvrt	d��|t|�g|j|<|j
t|t|�z�y)Nzalready opened this directory)	rrhr�rqr��iterr&r�r)rr�r�r�s    rr�z#FileTransferServer._cbOpenDirectory?s[���s�4��<�0�1���T�]�]�"��:�;�;�!'��f�� 6��
�
�f�����
�I��6�
�$:�;rc��|dd}|dd}t|�\}}|dk(s
Jd|����||jvr.|jtjt��|�y|j|\}}t
j|j|g�}|j|j|�|j|j|d�y)Nr)rzstill have data in READDIR: sscan directory failed)rrqr�r
r�r�r	r��_scanDirectoryr��_cbSendDirectoryr�)rr%r�r�r��dirIterr�s       r�packet_READDIRz!FileTransferServer.packet_READDIRFs�����!�H�	��A�B�x���T�{�����s�{�C�:�4�(�C�C�{�����&��N�N�7�?�?�8�:�6�	�B�"�m�m�F�3�O�F�G��#�#�D�$7�$7��"�E�A�
�M�M�$�/�/��;�
�L�L�����4L�Mrc��t|�dkrd	t|�}t	|t
j�r|j|j||�y|j|�t|�dkr�d|S#t$r
|st�|cYSwxYw)N�)
r#�next�
StopIterationr��
isinstancer	�Deferredr��_cbScanDirectoryrV)rr�r8r1s    rr�z!FileTransferServer._scanDirectorySs����!�f�s�l�
��G�}��
�$����/�� � ��!6�!6���C��������!�f�s�l����!�
��"�N���
�s�A5�5B�
Bc�H�|j|�|j||�Srn)rVr�)rr�r�r8s    rr�z#FileTransferServer._cbScanDirectorybs!��	������"�"�7�A�.�.rc
���d}|D]6\}}}|t|�z
}|t|�z
}||j|�z
}�8|jt|t	j
dt
|��z|z�y)Nrr;)rr\r&�FXP_NAMEr!r"r#)rr�r�r%r��longnamerMs       rr�z#FileTransferServer._cbSendDirectoryfsw����)/�	0�%�H�h���B�x�L� �D��B�x�L� �D��D�(�(��/�/�D�	0�	
����)�f�k�k�$��F��.L�"L�t�"S�Trc��|dd}|dd}t|�\}}|dk(s
Jd|����tj|jj||�}|j|j|�|j|j|d�y)Nr)rzstill have data in STAT/LSTAT: sstat/lstat failed)	rr	r�ro�getAttrsr��_cbStatr�r�)rr%�followLinksr�r�r�s      r�packet_STATzFileTransferServer.packet_STATns�����!�H�	��A�B�x���4�[�
��d��s�{�F�=�d�X�F�F�{������� 4� 4�d�K�H��	�
�
�d�l�l�I�.�	���T�^�^�Y�0D�Erc�(�|j|d�y�Nr)r�)rr%s  r�packet_LSTATzFileTransferServer.packet_LSTATws������q�!rc��|dd}|dd}t|�\}}|dk(s
Jd|����||jvr2|jtjt|�d���|�y|j|}t
j|j�}|j|j|�|j|j|d�y)Nr)rzstill have data in FSTAT: z not in self.openFilessfstat failed)rrpr�r
r�r�r	r�r�r�r�r�)rr%r�r�r�r�s      r�packet_FSTATzFileTransferServer.packet_FSTATzs�����!�H�	��A�B�x���T�{�����s�{�A�8���A�A�{�����'��N�N�����F�8�3I�)J� K�L��
�
�n�n�V�,�G��#�#�G�$4�$4�5�A�
�M�M�$�,�,�	�2�
�L�L�����O�Drc�X�||j|�z}|jt|�yrn)r\r&�	FXP_ATTRS)rr�r�r%s    rr�zFileTransferServer._cbStat�s%���4�/�/��7�7�����	�4�(rc�j�|dd}|dd}t|�\}}|j|�\}}|dk7r|jjd|��t	j
|jj||�}|j|j|d�|j|j|d�y)Nr)rz$Still have data in SETSTAT: {data!r})r%ssetstat succeededssetstat failed)rrSr0�warnr	r�ro�setAttrsr�r�r�r�r�s      r�packet_SETSTATz!FileTransferServer.packet_SETSTAT�s�����!�H�	��A�B�x���4�[�
��d��+�+�D�1���t��3�;��I�I�N�N�A��N�M������� 4� 4�d�E�B��	�
�
�d�n�n�i�1E�F�	���T�^�^�Y�0A�Brc���|dd}|dd}t|�\}}|j|�\}}|dk(s
Jd|����||jvr.|jt	j
t
��|�y|j|}tj|j|�}|j|j|d�|j|j|d�y)Nr)rzstill have data in FSETSTAT: sfsetstat succeededsfsetstat failed)
rrSrpr�r
r�r�r	r�r�r�r�r�)rr%r�r�rMr�r�s       r�packet_FSETSTATz"FileTransferServer.packet_FSETSTAT�s�����!�H�	��A�B�x���T�{�����+�+�D�1���t��s�{�D�;�D�8�D�D�{�����'��N�N�7�?�?�8�:�6�	�B��n�n�V�,�G��#�#�G�$4�$4�e�<�A�
�M�M�$�.�.�)�5J�K�
�L�L�����4F�Grc��|dd}|dd}t|�\}}|dk(s
Jd|����tj|jj|�}|j|j|�|j|j|d�y)Nr)rzstill have data in READLINK: sreadlink failed)	rr	r�ro�readLinkr��_cbReadLinkr�r�r�s     r�packet_READLINKz"FileTransferServer.packet_READLINK������!�H�	��A�B�x���4�[�
��d��s�{�D�;�D�8�D�D�{������� 4� 4�d�;��	�
�
�d�&�&�	�2�	���T�^�^�Y�0B�Crc�0�|j|difg|�yr)r�r�s   rr�zFileTransferServer._cbReadLink�s�������R�0�1�9�=rc��|dd}|dd}t|�\}}t|�\}}tj|jj||�}|j|j|d�|j|j|d�y)Nr)ssymlink succeededssymlink failed)	rr	r�ro�makeLinkr�r�r�r�)rr%r��linkPath�
targetPathr�s      r�packet_SYMLINKz!FileTransferServer.packet_SYMLINK�s{����!�H�	��A�B�x���t����$� ��;��
�D������� 4� 4�h�
�K��	�
�
�d�n�n�i�1E�F�	���T�^�^�Y�0A�Brc��|dd}|dd}t|�\}}|dk(s
Jd|����tj|jj|�}|j|j|�|j|j|d�y)Nr)rzstill have data in REALPATH: srealpath failed)	rr	r�ro�realPathr�r�r�r�r�s     r�packet_REALPATHz"FileTransferServer.packet_REALPATH�r�rc��|dd}|dd}t|�\}}tj|jj||�}|j|j|�|j|j|d|zdz�y)Nr)s	extended s failed)	rr	r�ro�extendedRequestr��_cbExtendedr�r�)rr%r�r|r[r�s      r�packet_EXTENDEDz"FileTransferServer.packet_EXTENDED�sv����!�H�	��A�B�x�� ��;���������� ;� ;�W�g�N��	�
�
�d�&�&�	�2�	���T�^�^�Y��w�0F��0S�Trc�6�|jt||z�yrn)r&�FXP_EXTENDED_REPLY)rr%r�s   rrzFileTransferServer._cbExtended�s�����*�I��,<�=rc�2�|j|t|�yrn)r3r�)rr�r��msgs    rr�zFileTransferServer._cbStatus�s������E�3�/rc��t}|}t|jttf�r�|jj
t
jk(r't}t|jj�}�n�|jj
t
jk(r't}t|jj�}�nq|jj
t
jk(rt}�nB|jjd|||���n!t|jt �r?t"}|jj$r�t|jj$d�}n�t|jt&�r?t(}|jj$r�t|jj$d�}not|jt*�r6|jj,}t|jj.�}n|jjd|||��|j1|||�y)Nz%Request {requestId} failed: {message})r
r��messagerz8Request {requestId} failed with unknown error: {message})�
FX_FAILUREr��value�IOErrorr�r�r��FX_NO_SUCH_FILErr��EACCES�FX_PERMISSION_DENIED�EEXIST�FX_FILE_ALREADY_EXISTSr0r
r��FX_EOF�args�NotImplementedErrorr4�	SFTPErrorr�rr3)rrar�rr�rs      rr�zFileTransferServer._ebStatus�s��������f�l�l�W�g�$6�7��|�|�!�!�U�\�\�1�&��'����(=�(=�>�����#�#�u�|�|�3�+��'����(=�(=�>�����#�#�u�|�|�3�-���	�	�!�!�;�"�'�#�	"������h�
/��D��|�|� � �'����(9�(9�!�(<�=��
����&9�
:�$�D��|�|� � �'����(9�(9�!�(<�=��
����i�
0��<�<�$�$�D�#�F�L�L�$8�$8�9�G��I�I���J��#��	
�
�	
����D�'�2rc��|tjd|�z}|t|�z
}|t|�z
}|jt|�y)z=
        Helper method to send a FXP_STATUS message.
        r;N)r!r"rr&�
FXP_STATUS)rr�r�r�langr%s      rr3zFileTransferServer._sendStatus�sC���6�;�;�t�T�2�2����7������4�������
�D�)rc��tj||�|jj�D]}|j	��i|_|j
j�D]\}}|j	��i|_y)z{
        Called when connection to the remote subsystem was lost.

        Clean all opened files and directories.
        N)rr_rp�valuesr�rq)rrar�r�r�s     rr_z!FileTransferServer.connectionLostsp��	�'�'��f�5��~�~�,�,�.�	�G��M�M�O�	����#�}�}�3�3�5�	�O�F�G��L�L�N�	���
r)NN�r)r)srequest succeeded)srequest failed)r)&rcrdrerr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�r�r3r_�rrrlrl�s����
S�
@�<�<�4;�D�:�
E� B�B�A�A�C�<�N�
�/�U�F�"�E� )�	C�H�D�>�C�D�U�>�0�%3�N*�rrlc��eZdZifd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zdd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�FileTransferClientc�X�tj|�i|_d|_i|_y)zq
        @param extData: a dict of extended_name : extended_data items
        to be sent to the server.
        rN)rrr[�counter�openRequests)rr[s  rrzFileTransferClient.__init__s(��
	�!�!�$�'���������rc��tjdt|j��}|jj�D]\}}|t
|�t
|�zz
}�!|jt|�y)Nr;)	r!r"�maxrfr[rrr&�FXP_INIT)rr%rYrs    r�connectionMadez!FileTransferClient.connectionMades_���{�{�4��T�]�]�!3�4���L�L�'�'�)�	"�D�A�q��B�q�E�B�q�E�M�!�D�	"�����$�'rc�N�tj||�|jr�tj�}|j
|_tj|�}|jr<|jj�\}}|j|�|jr�;yyy)zu
        Called when connection to the remote subsystem was lost.

        Any pending requests are aborted.
        N)rr_rr
�ConnectionLostr	�	__cause__r
r��popitem�errback)rra�requestError�requestFailure�_�deferreds      rr_z!FileTransferClient.connectionLost%s���	�'�'��f�5����!�/�/�1�L�%+�\�\�L�"�$�_�_�\�:�N��#�#�"�/�/�7�7�9���8�� � ��0��#�#�
rc�Z�|js'tjtj��Stjd|j�|z}tj�}||j|j<|xjdz
c_|j||�|S)z�
        Send a request and return a deferred which waits for the result.

        @type msg: L{int}
        @param msg: The request type (e.g., C{FXP_READ}).

        @type data: L{bytes}
        @param data: The body of the request.
        r;r)r`r	�failr
r%r!r"rr�rr&)rrr%r�s    r�_sendRequestzFileTransferClient._sendRequest:s}���~�~��:�:�e�2�2�4�5�5��{�{�4����.��5���N�N���*+����$�,�,�'�����������T�"��rc�~�tjd|dd�\}|j|}|j|=||ddfS�Nr;r))r!r.r)rr%�idr�s    r�
_parseRequestz FileTransferClient._parseRequestNsH���
�
�d�D��!�H�-������b�!�����b�!��$�q�r�(�{�rc���t|�tjd|�z|j|�z}|j	t
|�}|j
|jt|�|S)a�
        Open a file.

        This method returns a L{Deferred} that is called back with an object
        that provides the L{ISFTPFile} interface.

        @type filename: L{bytes}
        @param filename: a string representing the file to open.

        @param flags: an integer of the flags to open the file with, ORed together.
        The flags and their values are listed at the bottom of this file.

        @param attrs: a list of attributes to open the file with.  It is a
        dictionary, consisting of 0 or more keys.  The possible keys are::

            size: the size of the file in bytes
            uid: the user ID of the file as an integer
            gid: the group ID of the file as an integer
            permissions: the permissions of the file with as an integer.
            the bit representation of this field is defined by POSIX.
            atime: the access time of the file as seconds since the epoch.
            mtime: the modification time of the file as seconds since the epoch.
            ext_*: extended attributes.  The server is not required to
            understand this, but it may.

        NOTE: there is no way to indicate text or binary files.  it is up
        to the SFTP client to deal with this.
        r;)	rr!r"r\r/�FXP_OPENr��
_cbOpenHandle�
ClientFile)rr�rLrMr%r�s      rr�zFileTransferClient.openFileTsZ��:�(�|�f�k�k�$��6�6��9M�9M�e�9T�T�����h��-��	�
�
�d�(�(�*�h�?��rc�&�|||�}||_|S)a�
        Callback invoked when an OPEN or OPENDIR request succeeds.

        @param handle: The handle returned by the server
        @type handle: L{bytes}
        @param handleClass: The class that will represent the
        newly-opened file or directory to the user (either L{ClientFile} or
        L{ClientDirectory}).
        @param name: The name of the file or directory represented
        by C{handle}.
        @type name: L{bytes}
        )�name)rr��handleClassr9�cbs     rr6z FileTransferClient._cbOpenHandlevs����v�
&������	rc�@�|jtt|��S)z�
        Remove the given file.

        This method returns a Deferred that is called back when it succeeds.

        @type filename: L{bytes}
        @param filename: the name of the file as a string.
        )r/�
FXP_REMOVEr)rr�s  rr�zFileTransferClient.removeFile�s��� � ��R��\�:�:rc�X�|jtt|�t|�z�S)a
        Rename the given file.

        This method returns a Deferred that is called back when it succeeds.

        @type oldpath: L{bytes}
        @param oldpath: the current location of the file.
        @type newpath: L{bytes}
        @param newpath: the new file name.
        )r/�
FXP_RENAMEr)r�oldpath�newpaths   rr�zFileTransferClient.renameFile�s$��� � ��R��[�2�g�;�-F�G�Grc�d�|jtt|�|j|�z�S)au
        Make a directory.

        This method returns a Deferred that is called back when it is
        created.

        @type path: L{bytes}
        @param path: the name of the directory to create as a string.

        @param attrs: a dictionary of attributes to create the directory
        with.  Its meaning is the same as the attrs in the openFile method.
        )r/�	FXP_MKDIRrr\)rr�rMs   rr�z FileTransferClient.makeDirectory�s+��� � ��B�t�H�t�7K�7K�E�7R�,R�S�Src�@�|jtt|��S)a-
        Remove a directory (non-recursively)

        It is an error to remove a directory that has files or directories in
        it.

        This method returns a Deferred that is called back when it is removed.

        @type path: L{bytes}
        @param path: the directory to remove.
        )r/�	FXP_RMDIRr)rr�s  rr�z"FileTransferClient.removeDirectory�s��� � ��B�t�H�5�5rc��|jtt|��}|j|jt
|�|S)a�
        Open a directory for scanning.

        This method returns a Deferred that is called back with an iterable
        object that has a close() method.

        The close() method is called when the client is finished reading
        from the directory.  At this point, the iterable will no longer
        be used.

        The iterable returns triples of the form (filename, longname, attrs)
        or a Deferred that returns the same.  The sequence must support
        __getitem__, but otherwise may be any 'sequence-like' object.

        filename is the name of the file relative to the directory.
        logname is an expanded format of the filename.  The recommended format
        is:
        -rwxr-xr-x   1 mjos     staff      348911 Mar 25 14:29 t-filexfer
        1234567890 123 12345678 12345678 12345678 123456789012

        The first line is sample output, the second is the length of the field.
        The fields are: permissions, link count, user owner, group owner,
        size in bytes, modification time.

        attrs is a dictionary in the format of the attrs argument to openFile.

        @type path: L{bytes}
        @param path: the directory to open.
        )r/�FXP_OPENDIRrr�r6�ClientDirectory�rr�r�s   rr�z FileTransferClient.openDirectory�s5��<
���k�2�d�8�4��	�
�
�d�(�(�/�4�@��rc�V�|rt}nt}|j|t|��S)a�
        Return the attributes for the given path.

        This method returns a dictionary in the same format as the attrs
        argument to openFile or a Deferred that is called back with same.

        @type path: L{bytes}
        @param path: the path to return attributes for as a string.
        @param followLinks: a boolean.  if it is True, follow symbolic links
        and return attributes for the real path at the base.  if it is False,
        return attributes for the specified path.
        )�FXP_STAT�	FXP_LSTATr/r)rr�r��ms    rr�zFileTransferClient.getAttrs�s(����A��A�� � ��B�t�H�-�-rc�h�t|�|j|�z}|jt|�S)ad
        Set the attributes for the path.

        This method returns when the attributes are set or a Deferred that is
        called back when they are.

        @type path: L{bytes}
        @param path: the path to set attributes for as a string.
        @param attrs: a dictionary in the same format as the attrs argument to
        openFile.
        )rr\r/�FXP_SETSTAT)rr�rMr%s    rr�zFileTransferClient.setAttrs�s0���$�x�$�.�.�u�5�5��� � ��d�3�3rc�v�|jtt|��}|j|j�S)z�
        Find the root of a set of symbolic links.

        This method returns the target of the link, or a Deferred that
        returns the same.

        @type path: L{bytes}
        @param path: the path of the symlink to read.
        )r/�FXP_READLINKrr��_cbRealPathrIs   rr�zFileTransferClient.readLink�/��
���l�B�t�H�5���}�}�T�-�-�.�.rc�X�|jtt|�t|�z�S)a[
        Create a symbolic link.

        This method returns when the link is made, or a Deferred that
        returns the same.

        @type linkPath: L{bytes}
        @param linkPath: the pathname of the symlink as a string
        @type targetPath: L{bytes}
        @param targetPath: the path of the target of the link as a string.
        )r/�FXP_SYMLINKr)rr�r�s   rr�zFileTransferClient.makeLink
s$��� � ��b��l�R�
�^�.K�L�Lrc�v�|jtt|��}|j|j�S)z�
        Convert any path to an absolute path.

        This method returns the absolute path as a string, or a Deferred
        that returns the same.

        @type path: L{bytes}
        @param path: the path to convert as a string.
        )r/�FXP_REALPATHrr�rRrIs   rr�zFileTransferClient.realPathrSrc�:�|d\}}}|jd�}|S)Nrzutf-8)�decode)rr�r9r�rMs     rrRzFileTransferClient._cbRealPath(s%�� &�q�	���h���{�{�7�#���rc�F�|jtt|�|z�S)ak
        Make an extended request of the server.

        The method returns a Deferred that is called back with
        the result of the extended request.

        @type request: L{bytes}
        @param request: the name of the extended request to make.
        @type data: L{bytes}
        @param data: any other data that goes along with the request.
        )r/�FXP_EXTENDEDr)r�requestr%s   rr�z"FileTransferClient.extendedRequest-s ��� � ��r�'�{�T�/A�B�Brc���tjd|dd�\}|dd}i}|r$t|�\}}t|�\}}|||<|r�$||_|j	||�yr1)r!r.rrw�gotServerVersion)rr%rwr�rYrs      r�packet_VERSIONz!FileTransferClient.packet_VERSION;sn���]�]�4��b�q��2�
���A�B�x������D�k�G�A�t��D�k�G�A�t��A�a�D��������g�q�)rc��|j|�\}}tjd|dd�\}|dd}t|�dk\r.t	|�\}}t|�dk\rt	|�\}}nd}nd}d}|t
k(r|j
||f�y|tk(r|jt|��y|tk(r|jt|��y|jt|t|�|��yrt)r3r!r.r#rr��callbackrr(r�r4rrr)rr%r�r�rrs      r�
packet_STATUSz FileTransferClient.packet_STATUSFs����$�$�T�*���4��-�-��d�2�A�h�/����A�B�x���t�9��>��d��I�C���4�y�A�~�"�4�[�
��d����C��D��5�=�
�J�J��T�{�#�
�V�^�
�I�I�h�s�m�$�
�&�
&�
�I�I�)�#�.�/�
�I�I�i��l�3�&7��>�?rc�j�|j|�\}}t|�\}}|j|�yrn)r3rra)rr%r�r�r+s     r�
packet_HANDLEz FileTransferClient.packet_HANDLE\s/���$�$�T�*���4��$�K�	���	�
�
�6�rc�f�|j|�\}}|jt|�d�yr�)r3rar�rr%r�s   r�packet_DATAzFileTransferClient.packet_DATAas*���$�$�T�*���4�	�
�
�5��;�q�>�"rc�:�|j|�\}}tjd|dd�\}|dd}g}t|�D]F}t	|�\}}t	|�\}}|j|�\}}|j
|||f��H|j|�yr1)r3r!r.rKrrSrVra)	rr%r��count�filesrPr�r�rMs	         r�packet_NAMEzFileTransferClient.packet_NAMEes����$�$�T�*���4��=�=��t�B�Q�x�0����A�B�x�����u��	6�A�"�4�[�N�H�d�"�4�[�N�H�d��/�/��5�K�E�4��L�L�(�H�e�4�5�		6�
	
�
�
�5�rc�r�|j|�\}}|j|j|�d�yr�)r3rarSrfs   r�packet_ATTRSzFileTransferClient.packet_ATTRSqs2���$�$�T�*���4�	�
�
�4�(�(��.�q�1�2rc�N�|j|�\}}|j|�yrn)r3rarfs   r�packet_EXTENDED_REPLYz(FileTransferClient.packet_EXTENDED_REPLYus"���$�$�T�*���4�	�
�
�4�rc��y)aN
        Called when the client sends their version info.

        @param serverVersion: an integer representing the version of the SFTP
        protocol they are claiming.
        @param extData: a dictionary of extended_name : extended_data items.
        These items are sent by the client to indicate additional features.
        Nr)r�
serverVersionr[s   rr^z#FileTransferClient.gotServerVersionys�rNr)rcrdrerr#r_r/r3r�r6r�r�r�r�r�r�r�r�r�r�rRr�r_rbrdrgrkrmror^rrrrrs���!��(�1�*�(� �D�"	;�H�
T�6� �D.�&
4�/�M�/��
C�	*�@�,�
#�
�3��rrc�0�eZdZd�Zd�Zd�Zd�Zd�Zd�Zy)r7c�2�||_t|�|_yrn)�parentrr��rrtr�s   rrzClientFile.__init__�s�������j��rc�V�|jjt|j�Srn)rtr/�	FXP_CLOSEr�rs rr�zClientFile.close�����{�{�'�'�	�4�;�;�?�?rc��|jtjd||�z}|jj	t
|�S)Nr�)r�r!r"rtr/�FXP_READ)rr�r7r%s    rr�zClientFile.readChunk�s4���{�{�V�[�[����?�?���{�{�'�'��$�7�7rc��|jtjd|�zt|�z}|jjt|�S)Nr<)r�r!r"rrtr/�	FXP_WRITE)rr��chunkr%s    rr�zClientFile.writeChunk�s;���{�{�V�[�[��v�6�6��E��B���{�{�'�'�	�4�8�8rc�V�|jjt|j�Srn)rtr/�	FXP_FSTATr�rs rr�zClientFile.getAttrs�rxrc��|j|jj|�z}|jjt|�Srn)r�rtr\r/r)rrMr%s   rr�zClientFile.setAttrs�s6���{�{�T�[�[�8�8��?�?���{�{�'�'�	�4�8�8rN)	rcrdrerr�r�r�r�r�rrrr7r7�s"��!�@�8�9�@�9rr7c�:�eZdZd�Zd�Zd�Zd�Zd�ZeZd�Z	d�Z
y)	rHc�@�||_t|�|_g|_yrn)rtrr��
filesCacherus   rrzClientDirectory.__init__�s�������j�����rc�V�|jjt|j�Srn)rtr/�FXP_READDIRr�rs r�readzClientDirectory.read�s���{�{�'�'��T�[�[�A�Arc��|j�tjd�S|jj	t
|j�}d|_|Srn)r�r	�succeedrtr/rw�rr�s  rr�zClientDirectory.close�sA���;�;���=�=��&�&��K�K�$�$�Y����<������rc��|Srnrrs r�__iter__zClientDirectory.__iter__�s���rc�$�tjdtd��|jr|jj	d�S|j�
t��|j
�}|j|j|j�|S)NzeUsing twisted.conch.ssh.filetransfer.ClientDirectory as an iterator was deprecated in Twisted 18.9.0.�)�category�
stacklevelr)
�warningsr��DeprecationWarningr��popr�r��addCallbacks�
_cbReadDir�
_ebReadDirr�s  r�__next__zClientDirectory.__next__�sr���
�
�C�(��
	
��?�?��?�?�&�&�q�)�)��?�?�"��/�!��I�I�K��	���t������8��rc� �|dd|_|dS)Nrr)r�)r�namess  rr�zClientDirectory._cbReadDir�s�����)����Q�x�rc�t�|jt�d|_tjt��Srn)�trapr�r�r
r�r�)rras  rr�zClientDirectory._ebReadDir�s&�����H��������}��/�/rN)rcrdrerr�r�r�r�r�r�r�rrrrHrH�s-���
B����"�D��0rrHc�0�eZdZdd�Zed��Zdefd�Zy)rc�X�tj|�||_||_||_yrn)r5rr��_messager)r�	errorCode�errorMessagers    rrzSFTPError.__init__�s%�����4� ���	�$��
���	rc��|jS)zX
        A string received over the network that explains the error to a human.
        )r�rs rrzSFTPError.message�s���}�}�r�returnc�:�d|j�d|j��S)Nz
SFTPError z: )r�rrs r�__str__zSFTPError.__str__�s���D�I�I�;�b�����7�7rN)�)rcrdrer�propertyrrhr�rrrrr�s'����	��	�8��8rrrr�rr)r*��r=r(�
�r��
��������e�f�g�h�i����l� �@�FXP_)br�r�r!r��typingr�zope.interfacer�twisted.conch.interfacesrr�twisted.conch.ssh.commonrr�twisted.internetr	r
r�twisted.loggerr�twisted.pythonr
�twisted.python.compatrr�Protocolrrlrr7rHr5rr"rzr5rwrzr|rLrrO�FXP_FSETSTATrGr�r=rCrErWrKr?rQrUrr�r�r�r�r[rrF�FILEXFER_ATTR_UIDGIDrGrHrIrJ�FILEXFER_TYPE_REGULAR�FILEXFER_TYPE_DIRECTORY�FILEXFER_TYPE_SYMLINK�FILEXFER_TYPE_SPECIAL�FILEXFER_TYPE_UNKNOWN�FXF_READ�	FXF_WRITE�
FXF_APPEND�	FXF_CREAT�	FXF_TRUNC�FXF_EXCL�FXF_TEXTr�rrr
r�FX_BAD_MESSAGE�FX_NO_CONNECTION�FX_CONNECTION_LOSTr4r�FX_NOT_A_DIRECTORY�FX_FILE_IS_A_DIRECTORY�globals�grv�keysr9rUr	rrrr�<module>r�s#��
�	�
���&�;�.�3�3�!�"�=�I�x�(�(�I�Xn�)�n�bm�)�m�`
�Y��9�9��9�0-0�-0�`8�	�8�.
������
�	���
�	�
�	�
�	���������
�
��	��	���
��
�
�����
�
�
�
������	�������!��/��&��$��#���������������	�
�
��	��	�����	��	
������
�
�����������
 ��#���I�������N�7�D����v���$���.2�1�2�h��$�$�U�+�7��t�Ur

Zerion Mini Shell 1.0