
    Ii                     p   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKrS SKJ	r	  S SK
Jr  S SKJr  S SKJrJrJr  S SKJrJrJrJrJrJrJrJrJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2  S SK3J4r4  S S	K5J6r6  S S
K7J8r8  S SK9J:r:J;r;J<r<  S r=Sr> " S S\\:5      r? " S S\?5      r@g)    )hexlifyN)util)Channel)Message)INFODEBUGo777) BaseSFTPCMD_OPENDIR
CMD_HANDLE	SFTPErrorCMD_READDIRCMD_NAME	CMD_CLOSESFTP_FLAG_READSFTP_FLAG_WRITESFTP_FLAG_CREATESFTP_FLAG_TRUNCSFTP_FLAG_APPENDSFTP_FLAG_EXCLCMD_OPEN
CMD_REMOVE
CMD_RENAME	CMD_MKDIR	CMD_RMDIRCMD_STAT	CMD_ATTRS	CMD_LSTATCMD_SYMLINKCMD_SETSTATCMD_READLINKCMD_REALPATH
CMD_STATUSCMD_EXTENDEDSFTP_OKSFTP_EOFSFTP_NO_SUCH_FILESFTP_PERMISSION_DENIEDint64)SFTPAttributes)SSHException)SFTPFile)ClosingContextManagerbuc                      U R                  S5      $ ! [        [        4 a)     U R                  S5      s $ ! [         a    U s s $ f = ff = f)z
decode a string as ascii or utf8 if possible (as required by the sftp
protocol).  if neither works, just return a byte string because the server
probably doesn't know the filename's encoding.
asciizutf-8)encodeUnicodeErrorAttributeErrordecode)ss    :/venv/lib/python3.13/site-packages/paramiko/sftp_client.py_to_unicoder8   H   sR    xx  .) 	88G$$ 	H	s)    A7AAAAA   /c                   N  ^  \ rS rSrSrS r\S(S j5       rU 4S jrS r	S r
S)S jrS)S	 jrS*S
 jrS+S jr\rS r\rS rS r\4S jrS rS rS rS rS rS rS rS rS rS rS,S jr S r!S r"S-S jr#S.S jr$   S/S jr%   S/S  jr&S! r'S" r(S,S# jr)S$ r*S% r+S& r,S'r-U =r.$ )0
SFTPClientZ   z
SFTP client object.

Used to open an SFTP session across an open SSH `.Transport` and perform
remote file operations.

Instances of this class may be used as context managers.
c                 F   [         R                  " U 5        Xl        SU l        SU l        [
        R                  " 5       U l        SU l        [        R                  " 5       U l        [        U5      [        L a[  U R                  R                  5       n[        R                   " UR#                  5       S-   5      U l        UR'                  5       U l         U R)                  5       nU R/                  [0        SR3                  U5      5        g! [*         a    [-        S5      ef = f)ac  
Create an SFTP client from an existing `.Channel`.  The channel
should already have requested the ``"sftp"`` subsystem.

An alternate way to create an SFTP client context is by using
`from_transport`.

:param .Channel sock: an open `.Channel` using the ``"sftp"`` subsystem

:raises:
    `.SSHException` -- if there's an exception while negotiating sftp
F   Nz.sftpzEOF during negotiationz*Opened sftp connection (server version {}))r
   __init__sockultra_debugrequest_number	threadingLock_lock_cwdweakrefWeakValueDictionary
_expectingtyper   get_transportr   
get_loggerget_log_channelloggerget_hexdump_send_versionEOFErrorr+   _logr   format)selfr@   	transportserver_versions       r7   r?   SFTPClient.__init__d   s     	$	 ^^%
	!557: 		//1I//))+g5DK  )446D	9!//1N 			8??	
  	9788	9s   D
 
D c                 Z    UR                  X#S9nUc  gUR                  S5        U " U5      $ )a  
Create an SFTP client channel from an open `.Transport`.

Setting the window and packet sizes might affect the transfer speed.
The default settings in the `.Transport` class are the same as in
OpenSSH and should work adequately for both files transfers and
interactive sessions.

:param .Transport t: an open `.Transport` which is already
    authenticated
:param int window_size:
    optional window size for the `.SFTPClient` session.
:param int max_packet_size:
    optional max packet size for the `.SFTPClient` session..

:return:
    a new `.SFTPClient` object, referring to an sftp session (channel)
    across the transport

.. versionchanged:: 1.15
    Added the ``window_size`` and ``max_packet_size`` arguments.
)window_sizemax_packet_sizeNsftp)open_sessioninvoke_subsystem)clstrY   rZ   chans        r7   from_transportSFTPClient.from_transport   s<    0 ~~#  
 <f%4y    c                   > [        U[        5      (       a  U H  nU R                  " X/UQ76   M     g UR                  SS5      n[        TU ]  " USU-   /U R
                  R                  5       /[        U5      -   Q76   g )N%z%%z
[chan %s] )
isinstancelistrR   replacesuperr@   get_name)rT   levelmsgargsm	__class__s        r7   rR   SFTPClient._log   sw    c4  		%*T*  ++c4(CGLs" 99%%'(4:5rc   c                 d    U R                  [        S5        U R                  R                  5         g)zK
Close the SFTP session and its underlying channel.

.. versionadded:: 1.4
zsftp session closed.N)rR   r   r@   closerT   s    r7   rr   SFTPClient.close   s!     			$./		rc   c                     U R                   $ )z
Return the underlying `.Channel` object for this SFTP session.  This
might be useful for doing things like setting a timeout on the channel.

.. versionadded:: 1.7.1
)r@   rs   s    r7   get_channelSFTPClient.get_channel   s     yyrc   c                 b    U R                  U5       Vs/ s H  o"R                  PM     sn$ s  snf )a  
Return a list containing the names of the entries in the given
``path``.

The list is in arbitrary order.  It does not include the special
entries ``'.'`` and ``'..'`` even if they are present in the folder.
This method is meant to mirror ``os.listdir`` as closely as possible.
For a list of full `.SFTPAttributes` objects, see `listdir_attr`.

:param str path: path to list (defaults to ``'.'``)
)listdir_attrfilename)rT   pathfs      r7   listdirSFTPClient.listdir   s+     %)$5$5d$;<$;q

$;<<<s   ,c                    U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5      u  p#U[        :w  a  [        S5      eUR                  5       n/ n  U R	                  [        U5      u  p#U[        :w  a  [        S5      eUR                  5       n[        U5       H[  nUR                  5       nUR                  5       n	[        R                   " X8U	5      n
US:w  d  MB  US:w  d  MJ  UR#                  U
5        M]     M  ! [         a     Of = fU R	                  [$        U5        U$ )a]  
Return a list containing `.SFTPAttributes` objects corresponding to
files in the given ``path``.  The list is in arbitrary order.  It does
not include the special entries ``'.'`` and ``'..'`` even if they are
present in the folder.

The returned `.SFTPAttributes` objects will each have an additional
field: ``longname``, which may contain a formatted string of the file's
attributes, in unix format.  The content of this string will probably
depend on the SFTP server implementation.

:param str path: path to list (defaults to ``'.'``)
:return: list of `.SFTPAttributes` objects

.. versionadded:: 1.2
listdir({!r})Expected handleExpected name response...)_adjust_cwdrR   r   rS   _requestr   r   r   
get_binaryr   rQ   r   get_intrangeget_textr*   	_from_msgappendr   )rT   r{   r_   rl   handlefilelistcountirz   longnameattrs              r7   ry   SFTPClient.listdir_attr   s   " %		%//56{D1
?-..!{F; H} 899KKME5\<<><<>%//xHO(d*:OOD) "    	i(s   8D! !
D.-D.c              #   z  #    U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5      u  p4U[        :w  a  [        S5      eUR                  5       n[        5       n  [        U5       H4  nU R                  [        S5      [        U5      nUR                  U5        M6     U H  nU R                  5       u  p9[!        U	5      nUR#                  5       n
X:X  a  U[$        :X  a  U R'                  U5        UR#                  5       n[        U5       HN  nUR)                  5       nUR)                  5       n[*        R,                  " XLU5      nUS:w  d  MB  US:w  d  MJ  Uv   MP     M     [        5       nGM  ! [.         a    U R	                  [0        U5         gf = f7f)a  
Generator version of `.listdir_attr`.

See the API docs for `.listdir_attr` for overall details.

This function adds one more kwarg on top of `.listdir_attr`:
``read_aheads``, an integer controlling how many
``SSH_FXP_READDIR`` requests are made to the server. The default of 50
should suffice for most file listings as each request/response cycle
may contain multiple files (dependent on server implementation.)

.. versionadded:: 1.15
r   r   Nr   r   )r   rR   r   rS   r   r   r   r   
get_stringrg   r   _async_requestrJ   r   r   _read_packetr   r   r#   _convert_statusr   r*   r   rQ   r   )rT   r{   read_aheadsr_   rl   r   numsr   numpkt_datanew_numr   rz   r   r   s                  r7   listdir_iterSFTPClient.listdir_iter  sz     %		%//56{D1
?-..!v%
 {+A--d4j+vNCKK$ ,  C"&"3"3"5KA!(+C!kkmG~
? 005KKME"5\#&<<>#&<<>-778  %O(d2B"&J *  $ vE H  i0s7   A?F;C.F 4F <F F; F85F;7F88F;c                 n   U R                  U5      nU R                  [        SR                  X5      5        SnSU;   d  SU;   a	  U[        -  nSU;   d  SU;   d  SU;   a	  U[
        -  nSU;   a  U[        [        -  -  nSU;   a  U[        [        -  -  nSU;   a  U[        [        -  -  n[        5       nU R                  [        XU5      u  pgU[        :w  a  [        S5      eUR                  5       nU R                  [        S	R                  X[!        [#        U5      5      5      5        [%        XX#5      $ )
a  
Open a file on the remote server.  The arguments are the same as for
Python's built-in `python:file` (aka `python:open`).  A file-like
object is returned, which closely mimics the behavior of a normal
Python file object, including the ability to be used as a context
manager.

The mode indicates how the file is to be opened: ``'r'`` for reading,
``'w'`` for writing (truncating an existing file), ``'a'`` for
appending, ``'r+'`` for reading/writing, ``'w+'`` for reading/writing
(truncating an existing file), ``'a+'`` for reading/appending.  The
Python ``'b'`` flag is ignored, since SSH treats all files as binary.
The ``'U'`` flag is supported in a compatible way.

Since 1.5.2, an ``'x'`` flag indicates that the operation should only
succeed if the file was created and did not previously exist.  This has
no direct mapping to Python's file flags, but is commonly known as the
``O_EXCL`` flag in posix.

The file will be buffered in standard Python style by default, but
can be altered with the ``bufsize`` parameter.  ``<=0`` turns off
buffering, ``1`` uses line buffering, and any number greater than 1
(``>1``) uses that specific buffer size.

:param str filename: name of the file to open
:param str mode: mode (Python-style) to open in
:param int bufsize: desired buffering (default: ``-1``)
:return: an `.SFTPFile` object representing the open file

:raises: ``IOError`` -- if the file could not be opened.
zopen({!r}, {!r})r   r+waxr   zopen({!r}, {!r}) -> {})r   rR   r   rS   r   r   r   r   r   r   r*   r   r   r   r   r   r/   r   r,   )	rT   rz   modebufsizeimode	attrblockr_   rl   r   s	            r7   openSFTPClient.openF  s#   @ ##H-		%+228BC4KSD[^#E4KSD[cTk_$E$;%77E$;%(888E$;%66E"$	x)D
?-..!		$++'&/ 2	
 d44rc   c                     U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5        g)z
Remove the file at the given path.  This only works on files; for
removing folders (directories), use `rmdir`.

:param str path: path (absolute or relative) of the file to remove

:raises: ``IOError`` -- if the path refers to a folder (directory)
zremove({!r})N)r   rR   r   rS   r   r   rT   r{   s     r7   removeSFTPClient.remove  s;     %		%..t45j$'rc   c                     U R                  U5      nU R                  U5      nU R                  [        SR                  X5      5        U R	                  [
        X5        g)a  
Rename a file or folder from ``oldpath`` to ``newpath``.

.. note::
    This method implements 'standard' SFTP ``RENAME`` behavior; those
    seeking the OpenSSH "POSIX rename" extension behavior should use
    `posix_rename`.

:param str oldpath:
    existing name of the file or folder
:param str newpath:
    new name for the file or folder, must not exist already

:raises:
    ``IOError`` -- if ``newpath`` is a folder, or something else goes
    wrong
zrename({!r}, {!r})N)r   rR   r   rS   r   r   rT   oldpathnewpaths      r7   renameSFTPClient.rename  sL    $ ""7+""7+		%-44WFGj'3rc   c                     U R                  U5      nU R                  U5      nU R                  [        SR                  X5      5        U R	                  [
        SX5        g)a  
Rename a file or folder from ``oldpath`` to ``newpath``, following
posix conventions.

:param str oldpath: existing name of the file or folder
:param str newpath: new name for the file or folder, will be
    overwritten if it already exists

:raises:
    ``IOError`` -- if ``newpath`` is a folder, posix-rename is not
    supported by the server or something else goes wrong

:versionadded: 2.2
zposix_rename({!r}, {!r})zposix-rename@openssh.comN)r   rR   r   rS   r   r$   r   s      r7   posix_renameSFTPClient.posix_rename  sR     ""7+""7+		%3::7LM4g	
rc   c                     U R                  U5      nU R                  [        SR                  X5      5        [	        5       nX#l        U R                  [        X5        g)aC  
Create a folder (directory) named ``path`` with numeric mode ``mode``.
The default mode is 0777 (octal).  On some systems, mode is ignored.
Where it is used, the current umask value is first masked out.

:param str path: name of the folder to create
:param int mode: permissions (posix-style) for the newly-created folder
zmkdir({!r}, {!r})N)r   rR   r   rS   r*   st_moder   r   rT   r{   r   r   s       r7   mkdirSFTPClient.mkdir  sI     %		%,33D?@i,rc   c                     U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5        g)zR
Remove the folder named ``path``.

:param str path: name of the folder to remove
zrmdir({!r})N)r   rR   r   rS   r   r   r   s     r7   rmdirSFTPClient.rmdir  s;     %		%--d34i&rc   c                     U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5      u  p#U[        :w  a  [        S5      e[        R                  " U5      $ )a  
Retrieve information about a file on the remote system.  The return
value is an object whose attributes correspond to the attributes of
Python's ``stat`` structure as returned by ``os.stat``, except that it
contains fewer fields.  An SFTP server may return as much or as little
info as it wants, so the results may vary from server to server.

Unlike a Python `python:stat` object, the result may not be accessed as
a tuple.  This is mostly due to the author's slack factor.

The fields supported are: ``st_mode``, ``st_size``, ``st_uid``,
``st_gid``, ``st_atime``, and ``st_mtime``.

:param str path: the filename to stat
:return:
    an `.SFTPAttributes` object containing attributes about the given
    file
z
stat({!r})Expected attributes)
r   rR   r   rS   r   r   r   r   r*   r   rT   r{   r_   rl   s       r7   statSFTPClient.stat  sc    & %		%,,T23x.	>122'',,rc   c                     U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5      u  p#U[        :w  a  [        S5      e[        R                  " U5      $ )a  
Retrieve information about a file on the remote system, without
following symbolic links (shortcuts).  This otherwise behaves exactly
the same as `stat`.

:param str path: the filename to stat
:return:
    an `.SFTPAttributes` object containing attributes about the given
    file
zlstat({!r})r   )
r   rR   r   rS   r   r   r   r   r*   r   r   s       r7   lstatSFTPClient.lstat  sc     %		%--d34y$/	>122'',,rc   c                     U R                  U5      nU R                  [        SR                  X5      5        [	        U5      nU R                  [        X5        g)z
Create a symbolic link to the ``source`` path at ``destination``.

:param str source: path of the original file
:param str dest: path of the newly created symlink
zsymlink({!r}, {!r})N)r   rR   r   rS   r.   r   r   )rT   sourcedests      r7   symlinkSFTPClient.symlink  sE     %		%.55fCD6k60rc   c                     U R                  U5      nU R                  [        SR                  X5      5        [	        5       nX#l        U R                  [        X5        g)z
Change the mode (permissions) of a file.  The permissions are
unix-style and identical to those used by Python's `os.chmod`
function.

:param str path: path of the file to change the permissions of
:param int mode: new permissions
zchmod({!r}, {!r})N)r   rR   r   rS   r*   r   r   r    r   s       r7   chmodSFTPClient.chmod  sI     %		%,33D?@k4.rc   c                     U R                  U5      nU R                  [        SR                  XU5      5        [	        5       nX#sUl        Ul        U R                  [        X5        g)a^  
Change the owner (``uid``) and group (``gid``) of a file.  As with
Python's `os.chown` function, you must pass both arguments, so if you
only want to change one, use `stat` first to retrieve the current
owner and group.

:param str path: path of the file to change the owner and group of
:param int uid: new owner's uid
:param int gid: new group id
zchown({!r}, {!r}, {!r})N)	r   rR   r   rS   r*   st_uidst_gidr   r    )rT   r{   uidgidr   s        r7   chownSFTPClient.chown  sT     %		%299$SIJ#& T[k4.rc   c                 (   U R                  U5      nUc*  [        R                  " 5       [        R                  " 5       4nU R                  [        SR	                  X5      5        [        5       nUu  Ul        Ul        U R                  [        X5        g)aT  
Set the access and modified times of the file specified by ``path``.
If ``times`` is ``None``, then the file's access and modified times
are set to the current time.  Otherwise, ``times`` must be a 2-tuple
of numbers, of the form ``(atime, mtime)``, which is used to set the
access and modified times, respectively.  This bizarre API is mimicked
from Python for the sake of consistency -- I apologize.

:param str path: path of the file to modify
:param tuple times:
    ``None`` or a tuple of (access time, modified time) in standard
    internet epoch time (seconds since 01 January 1970 GMT)
Nzutime({!r}, {!r}))
r   timerR   r   rS   r*   st_atimest_mtimer   r    )rT   r{   timesr   s       r7   utimeSFTPClient.utime0  sm     %=YY[$))+.E		%,33D@A',$t}k4.rc   c                     U R                  U5      nU R                  [        SR                  X5      5        [	        5       nX#l        U R                  [        X5        g)a   
Change the size of the file specified by ``path``.  This usually
extends or shrinks the size of the file, just like the `~file.truncate`
method on Python file objects.

:param str path: path of the file to modify
:param int size: the new size of the file
ztruncate({!r}, {!r})N)r   rR   r   rS   r*   st_sizer   r    )rT   r{   sizer   s       r7   truncateSFTPClient.truncateF  sI     %		%/66tBCk4.rc   c                 h   U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5      u  p#U[        :w  a  [        S5      eUR                  5       nUS:X  a  gUS:w  a  [        SR                  U5      5      e[        UR                  5       5      $ )z
Return the target of a symbolic link (shortcut).  You can use
`symlink` to create these.  The result may be either an absolute or
relative pathname.

:param str path: path of the symbolic link file
:return: target path, as a `str`
zreadlink({!r})r   r   Nr>   zReadlink returned {} results)r   rR   r   rS   r   r!   r   r   r   r8   r   rT   r{   r_   rl   r   s        r7   readlinkSFTPClient.readlinkU  s     %		%)0067|T2=455A:A::AA%HII3>>+,,rc   c                 H   U R                  U5      nU R                  [        SR                  U5      5        U R	                  [
        U5      u  p#U[        :w  a  [        S5      eUR                  5       nUS:w  a  [        SR                  U5      5      eUR                  5       $ )a  
Return the normalized path (on the server) of a given path.  This
can be used to quickly resolve symbolic links or determine what the
server is considering to be the "current folder" (by passing ``'.'``
as ``path``).

:param str path: path to be normalized
:return: normalized form of the given path (as a `str`)

:raises: ``IOError`` -- if the path can't be resolved on the server
znormalize({!r})r   r>   zRealpath returned {} results)
r   rR   r   rS   r   r"   r   r   r   r   r   s        r7   	normalizeSFTPClient.normalizej  s     %		%*11$78|T2=455A::AA%HII||~rc   c                 @   Uc  SU l         g[        R                  " U R                  U5      R                  5      (       d@  [        R
                  n[        USR                  [        R                  " U5      U5      5      e[        U R                  U5      5      U l         g)a  
Change the "current directory" of this SFTP session.  Since SFTP
doesn't really have the concept of a current working directory, this is
emulated by Paramiko.  Once you use this method to set a working
directory, all operations on this `.SFTPClient` object will be relative
to that path. You can pass in ``None`` to stop using a current working
directory.

:param str path: new current working directory

:raises:
    ``IOError`` -- if the requested path doesn't exist on the server

.. versionadded:: 1.4
Nz{}: {})rF   r   S_ISDIRr   errnoENOTDIRr   rS   osstrerrorr.   r   )rT   r{   codes      r7   chdirSFTPClient.chdir  so      <DI||DIIdO3344==DD(//"++d2CT"JKKdnnT*+	rc   c                 R    U R                   =(       a    [        U R                   5      $ )z
Return the "current working directory" for this SFTP session, as
emulated by Paramiko.  If no directory has been set with `chdir`,
this method will return ``None``.

.. versionadded:: 1.4
)rF   r/   rs   s    r7   getcwdSFTPClient.getcwd  s     yy)Qtyy\)rc   c                     Sn UR                  S5      nUR                  U5        U[        U5      -  n[        U5      S:X  a   U$ Ub  U" XS5        MO  )Nr   i   )readwritelen)rT   readerwriter	file_sizecallbackr   datas          r7   _transfer_with_callback"SFTPClient._transfer_with_callback  s\    ;;u%DLLCID4yA~  #) rc   c                 T   U R                  US5       nUR                  S5        U R                  XX4S9nSSS5        U(       aI  U R                  U5      nUR                  W:w  a%  [        SR                  UR                  U5      5      e U$ [        5       nU$ ! , (       d  f       Nj= f)aG  
Copy the contents of an open file object (``fl``) to the SFTP server as
``remotepath``. Any exception raised by operations will be passed
through.

The SFTP operations use pipelining for speed.

:param fl: opened file or file-like object to copy
:param str remotepath: the destination path on the SFTP server
:param int file_size:
    optional size parameter passed to callback. If none is specified,
    size defaults to 0
:param callable callback:
    optional callback function (form: ``func(int, int)``) that accepts
    the bytes transferred so far and the total bytes to be transferred
    (since 1.7.4)
:param bool confirm:
    whether to do a stat() on the file afterwards to confirm the file
    size (since 1.7.7)

:return:
    an `.SFTPAttributes` object containing attributes about the given
    file.

.. versionadded:: 1.10
wbTr   r   r   r   Nzsize mismatch in put!  {} != {})fileset_pipelinedr   r   r   IOErrorrS   r*   )	rT   fl
remotepathr   r   confirmfrr   r6   s	            r7   putfoSFTPClient.putfo  s    6 YYz4(BT"//	 0 D )
 		*%AyyD 5<<QYYM  !   A )(s   "B
B'c                     [         R                  " U5      R                  n[        US5       nU R	                  XbXSU5      sSSS5        $ ! , (       d  f       g= f)a  
Copy a local file (``localpath``) to the SFTP server as ``remotepath``.
Any exception raised by operations will be passed through.  This
method is primarily provided as a convenience.

The SFTP operations use pipelining for speed.

:param str localpath: the local file to copy
:param str remotepath: the destination path on the SFTP server. Note
    that the filename should be included. Only specifying a directory
    may result in an error.
:param callable callback:
    optional callback function (form: ``func(int, int)``) that accepts
    the bytes transferred so far and the total bytes to be transferred
:param bool confirm:
    whether to do a stat() on the file afterwards to confirm the file
    size

:return: an `.SFTPAttributes` object containing attributes about the
    given file

.. versionadded:: 1.4
.. versionchanged:: 1.7.4
    ``callback`` and rich attribute return value added.
.. versionchanged:: 1.7.7
    ``confirm`` param added.
rbN)r   r   r   r   r  )rT   	localpathr	  r   r
  r   r  s          r7   putSFTPClient.put  s@    8 GGI&..	)T"b::bi7K #""s   A


Ac                     U R                  U5      R                  nU R                  US5       nU(       a  UR                  Xe5        U R	                  XrXcS9sSSS5        $ ! , (       d  f       g= f)a'  
Copy a remote file (``remotepath``) from the SFTP server and write to
an open file or file-like object, ``fl``.  Any exception raised by
operations will be passed through.  This method is primarily provided
as a convenience.

:param object remotepath: opened file or file-like object to copy to
:param str fl:
    the destination path on the local host or open file object
:param callable callback:
    optional callback function (form: ``func(int, int)``) that accepts
    the bytes transferred so far and the total bytes to be transferred
:param bool prefetch:
    controls whether prefetching is performed (default: True)
:param int max_concurrent_prefetch_requests:
    The maximum number of concurrent read requests to prefetch. See
    `.SFTPClient.get` (its ``max_concurrent_prefetch_requests`` param)
    for details.
:return: the `number <int>` of bytes written to the opened file object

.. versionadded:: 1.10
.. versionchanged:: 2.8
    Added the ``prefetch`` keyword argument.
.. versionchanged:: 3.3
    Added ``max_concurrent_prefetch_requests``.
r  r  N)r   r   r   prefetchr   )rT   r	  r  r   r   max_concurrent_prefetch_requestsr   r  s           r7   getfoSFTPClient.getfo  s\    D IIj)11	YYz4(BIH//	 0  )((s   (A  
A.c                    [        US5       nU R                  UUUUU5      nSSS5        [        R                  " U5      nUR                  W:w  a%  [        SR                  UR                  U5      5      eg! , (       d  f       NZ= f)a  
Copy a remote file (``remotepath``) from the SFTP server to the local
host as ``localpath``.  Any exception raised by operations will be
passed through.  This method is primarily provided as a convenience.

:param str remotepath: the remote file to copy
:param str localpath: the destination path on the local host
:param callable callback:
    optional callback function (form: ``func(int, int)``) that accepts
    the bytes transferred so far and the total bytes to be transferred
:param bool prefetch:
    controls whether prefetching is performed (default: True)
:param int max_concurrent_prefetch_requests:
    The maximum number of concurrent read requests to prefetch.
    When this is ``None`` (the default), do not limit the number of
    concurrent prefetch requests. Note: OpenSSH's sftp internally
    imposes a limit of 64 concurrent requests, while Paramiko imposes
    no limit by default; consider setting a limit if a file can be
    successfully received with sftp but hangs with Paramiko.

.. versionadded:: 1.4
.. versionchanged:: 1.7.4
    Added the ``callback`` param
.. versionchanged:: 2.8
    Added the ``prefetch`` keyword argument.
.. versionchanged:: 3.3
    Added ``max_concurrent_prefetch_requests``.
r  Nzsize mismatch in get!  {} != {})r   r  r   r   r   r  rS   )	rT   r	  r  r   r  r  r  r   r6   s	            r7   getSFTPClient.get#  s~    H )T"b::0D # GGI99188DI   #"s   A77
Bc                 ^    U R                   " [        S 5      U/UQ76 nU R                  U5      $ N)r   rJ   _read_response)rT   r_   rm   r   s       r7   r   SFTPClient._requestW  s.    !!$t*a7$7""3''rc   c                    U R                   R                  5          [        5       nUR                  U R                  5        U H  n[        U[        5      (       a  UR                  U5        M+  [        U[        5      (       a  UR                  U5        MS  [        U[        5      (       a  UR                  U5        M{  UR                  U5        M     U R                  nXR                  U'   U =R                  S-  sl        U R                   R                  5         U R                  X$5        U$ ! U R                   R                  5         f = f)Nr>   )rE   acquirer   add_intrB   rf   r)   	add_int64intr*   _pack
add_stringrI   release_send_packet)rT   fileobjr_   rm   rl   itemr   s          r7   r   SFTPClient._async_request[  s    

	!)CKK++,dE**MM$'c**KK%n55JJsO NN4(  %%C#*OOC 1$JJ !!
 JJ s   C&D/ /Ec                      U R                  5       u  p#[	        U5      nUR                  5       nU R                  R                  5          X`R                  ;  aa  U R                  [        SR                  U5      5        Uc   U R                  R                  5         g U R                  R                  5         M  U R                  U   nU R                  U	 U R                  R                  5         Xa:X  a  U[        :X  a  U R                  U5        X%4$ U[        S 5      La  UR                  X%U5        Uc   gGM:  ! [         a  n[        SR                  U5      5      eS nAff = f! U R                  R                  5         f = f)NzServer connection dropped: {}zUnexpected response #{}NN)r   rQ   r+   rS   r   r   rE   r   rI   rR   r   r&  r#   r   rJ   _async_response)rT   waitforr_   r   erl   r   r(  s           r7   r  SFTPClient._read_responset  s\   N++- $-C++-CJJ %oo- IIe%>%E%Ec%JK
 

""$ %  

""$ //#.OOC(

""$~
?((-v d4j(''4E   N"#B#I#I!#LMMN" 

""$s)   D< 7E( ;E( <
E%E  E%(Fc                     XR                   R                  5       ;   a@  U R                  5         UR                  5         XR                   R                  5       ;   a  M?  g g r  )rI   valuesr  _check_exception)rT   r(  s     r7   _finish_responsesSFTPClient._finish_responses  sB    //11!$$& //11rc   c                 (   UR                  5       nUR                  5       nU[        :X  a  gU[        :X  a  [	        U5      eU[
        :X  a  [        [        R                  U5      eU[        :X  a  [        [        R                  U5      e[        U5      e)zE
Raises EOFError or IOError on error status; otherwise does nothing.
N)r   r   r%   r&   rQ   r'   r  r   ENOENTr(   EACCES)rT   rl   r   texts       r7   r   SFTPClient._convert_status  st     {{}||~7?X4. &&%,,--++%,,--$-rc   c                     [        U5      nU R                  c  U$ [        U5      (       a  USS [        :X  a  U$ U R                  [        :X  a  U R                  U-   $ U R                  [        -   U-   $ )zZ
Return an adjusted path if we're emulating a "current working
directory" for the server.
r   r>   )r.   rF   r   b_slashr   s     r7   r   SFTPClient._adjust_cwd  sf    
 w99Kt99ag-K9999t##yy7"T))rc   )rF   rI   rE   rN   rB   r@   rA   r,  )r   )r   2   )r   r  )r   NT)NT)NTN)/__name__
__module____qualname____firstlineno____doc__r?   classmethodra   rR   rr   rv   r}   ry   r   r   r  r   unlinkr   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r   r  r4  r   r   __static_attributes____classcell__)ro   s   @r7   r;   r;   Z   s   &
P  > =(T>@85v D( F4.
,  $ -'-4-$
1//"/,/-*,,0	*
(TLH )-(\ )-0h(2#J'
 $* *rc   r;   c                       \ rS rSrSrSrg)SFTPi  z9
An alias for `.SFTPClient` for backwards compatibility.
 N)r@  rA  rB  rC  rD  rG  rK  rc   r7   rJ  rJ    s     	rc   rJ  )Abinasciir   r   r   r   rC   r   rG   paramikor   paramiko.channelr   paramiko.messager   paramiko.commonr   r   r	   paramiko.sftpr
   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%   r&   r'   r(   r)   paramiko.sftp_attrr*   paramiko.ssh_exceptionr+   paramiko.sftp_filer,   paramiko.utilr-   r.   r/   r8   r<  r;   rJ  rK  rc   r7   <module>rV     s   (   	      $ $ - -! ! ! ! ! ! ! ! !F . / ' 5 5 c*0 c*L	: 	rc   