
    7Th                         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Jr  S SKrSSK	J
r
  SSKJr  \R                  " S5      r " S S\
5      rS	 rS
 rg)    N)S_ISDIRS_ISLNK   )AbstractFileSysteminfer_storage_optionszfsspec.sftpc                      ^  \ rS rSrSrSrU 4S jrS r\S 5       r	\
S 5       rSS jrSS	 jrS
 rS r\
SS j5       rSS jrSS jrS rSS jrS rS rSrU =r$ )SFTPFileSystem   zFiles over SFTP/SSH

Peer-to-peer filesystem over SSH using paramiko.

Note: if using this with the ``open`` or ``open_files``, with full URLs,
there is no way to tell if a path is relative, so all paths are assumed
to be absolute.
)sftpsshc                    > U R                   (       a  g[        TU ]  " S0 UD6  UR                  SS5      U l        Xl        X l        U R                  5         g)a]  

Parameters
----------
host: str
    Hostname or IP as a string
temppath: str
    Location on the server to put files, when within a transaction
ssh_kwargs: dict
    Parameters passed on to connection. See details in
    https://docs.paramiko.org/en/3.3/api/client.html#paramiko.client.SSHClient.connect
    May include port, username, password...
Ntemppathz/tmp )_cachedsuper__init__popr   host
ssh_kwargs_connect)selfr   r   	__class__s      S/var/www/auris/envauris/lib/python3.13/site-packages/fsspec/implementations/sftp.pyr   SFTPFileSystem.__init__   sD     <<&:&"z6:	$    c                 t   [         R                  SU R                  5        [        R                  " 5       U l        U R
                  R                  [        R                  " 5       5        U R
                  R                  " U R                  40 U R                  D6  U R
                  R                  5       U l        g )NzConnecting to SFTP server %s)loggerdebugr   paramiko	SSHClientclientset_missing_host_key_policyAutoAddPolicyconnectr   	open_sftpftpr   s    r   r   SFTPFileSystem._connect2   ss    3TYY?((*//0F0F0HIDII99;;((*r   c                     [        U5      S   $ )Npathr   )clsr+   s     r   _strip_protocolSFTPFileSystem._strip_protocol9   s    $T*622r   c                 d    [        U 5      nUR                  SS 5        UR                  SS 5        U$ )Nr+   protocol)r   r   )urlpathouts     r   _get_kwargs_from_urls$SFTPFileSystem._get_kwargs_from_urls=   s-    #G,
D!
r   c                     [         R                  SU5        U R                  U5      (       a  [        SU 35      eU(       a  U R	                  U5        g U R
                  R                  X5        g )NzCreating folder %sFile exists: )r   r   existsFileExistsErrormakedirsr'   mkdir)r   r+   create_parentsmodes       r   r:   SFTPFileSystem.mkdirD   sQ    )40;;t!M$"899MM$HHNN4&r   c                 @   U R                  U5      (       a  U(       d  [        SU 35      eUR                  S5      nUS S S:X  a  SOSnU HO  nU(       d  M  U(       a  U SU 3OUnU R                  U5      (       a  M4  U R                  R	                  XS5        MQ     g )Nr6   /    )r7   r8   splitr'   r:   )r   r+   exist_okr<   partsnew_pathparts          r   r9   SFTPFileSystem.makedirsN   s    ;;tX!M$"899

3r(c/3rDt3;hZq/{{8,,HHNN82	 r   c                 f    [         R                  SU5        U R                  R                  U5        g )NzRemoving folder %s)r   r   r'   rmdirr   r+   s     r   rI   SFTPFileSystem.rmdir[   s!    )40tr   c                 b    U R                  U R                  R                  U5      5      nXS'   U$ )Nname)_decode_statr'   stat)r   r+   rO   s      r   infoSFTPFileSystem.info_   s+      t!45Vr   c                 2   [        U R                  5      (       a  SnO[        U R                  5      (       a  SnOSnSU R                  UU R                  U R
                  [        R                  R                  U R                  [        R                  R                  S9[        R                  R                  U R                  [        R                  R                  S9S.nU(       a/  SR                  UR                  S5      U R                  /5      US'   U$ )	N	directorylinkfilerA   )tz)rM   sizetypeuidgidtimemtimer?   rM   )r   st_moder   st_sizest_uidst_giddatetimefromtimestampst_atimetimezoneutcst_mtimejoinrstripfilename)rO   parent_pathtr2   s       r   rN   SFTPFileSystem._decode_statd   s    4<<  AT\\""AALL;;;;%%33("3"3"7"7 4  &&44("3"3"7"7 5 
 ((K$6$6s$;T]]#KLCK
r   c                    [         R                  SU5        U R                  R                  U5       Vs/ s H  o0R	                  X15      PM     nnU(       a  U$ U Vs/ s H  o3S   PM	     nn[        U5      $ s  snf s  snf )NzListing folder %srM   )r   r   r'   listdir_iterrN   sorted)r   r+   detailrO   statspathss         r   lsSFTPFileSystem.ls}   ss    ($/;?88;P;PQU;VW;V4""4.;VWL.34ed&\eE4%=  X 5s   A8A=c                 f    [         R                  SX5        U R                  R                  X5        g )NzPut file %s into %s)r   r   r'   put)r   lpathrpathcallbackkwargss        r   rv   SFTPFileSystem.put   s!    *E9U"r   c                     U R                  U5      (       a  [        R                  " USS9  g U R                  R	                  U R                  U5      U5        g )NT)rC   )isdirosr9   r'   getr-   )r   rx   rw   rz   s       r   get_fileSFTPFileSystem.get_file   s<    ::eKK-HHLL--e4e<r   c                    [         R                  SU5        UR                  SS5      SL a  SR                  U R                  [        [        R                  " 5       5      /5      nU R                  R                  XRU(       a  UOSS9nXVl        Xl
        Xl        [        R                  " [        U5      Ul        [        R                  " [         U5      Ul        U$ U R                  R                  XU(       a  UOSS9nU$ )z
block_size: int or None
    If 0, no buffering, if 1, line buffering, if >1, buffer that many
    bytes, if None use default from paramiko.
zOpening file %s
autocommitTFr?   )bufsize)r   r   r   rg   r   struuiduuid4r'   open
targetpathfstypes
MethodTypecommit_a_filecommitdiscard_a_filediscard)r   r+   r<   
block_sizerz   path2fs          r   _openSFTPFileSystem._open   s     	&-::lD)U2HHdmmS->?@Ee:QSTAJLD''q9AH((;AI  d
*PRSAr   c                     U R                  U5      (       a  U R                  R                  U5        g U R                  R                  U5        g N)r}   r'   rI   removerJ   s     r   _rmSFTPFileSystem._rm   s1    ::dHHNN4 HHOOD!r   c                 f    [         R                  SX5        U R                  R                  X5        g )NzRenaming %s into %s)r   r   r'   posix_rename)r   oldnews      r   mvSFTPFileSystem.mv   s#    *C5c'r   )r"   r'   r   r   r   )T  )Fr   r   )F)rbN)__name__
__module____qualname____firstlineno____doc__r0   r   r   classmethodr-   staticmethodr3   r:   r9   rI   rP   rN   rs   rv   r   r   r   r   __static_attributes____classcell__)r   s   @r   r
   r
      s     H,+ 3 3  '3
  0!#=("( (r   r
   c                 d    U R                   R                  U R                  U R                  5        g r   )r   r   r   r   r(   s    r   r   r      s    GGJJt}}doo.r   c                 N    U R                   R                  U R                  5        g r   )r   r   r   r(   s    r   r   r      s    GGKKr   )ra   loggingr~   r   r   rO   r   r   r    rA   r   utilsr   	getLoggerr   r
   r   r   r   r   r   <module>r      sJ      	   !  ! )			=	)\(' \(~/r   