L i#ddlZddlZddlZddlZddlZddlmZmZddlZddl m Z ddl m Z ejdZGdde Zd Zd Zy) N)S_ISDIRS_ISLNK)AbstractFileSysteminfer_storage_optionsz fsspec.sftpceZdZdZdZfdZdZedZe dZ ddZ ddZ d Z d Ze dd Zdd Zdd ZdZddZdZdZxZS)SFTPFileSystemzFiles 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. )sftpsshc |jryt|di||jdd|_||_||_|jy)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... Ntemppathz/tmp)_cachedsuper__init__poprhost ssh_kwargs_connect)selfrr __class__s a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fsspec/implementations/sftp.pyrzSFTPFileSystem.__init__sH <<  &:&"z6:  $ cptjd|jtj|_|j j tj|j j|jfi|j|j j|_ y)NzConnecting to SFTP server %s) loggerdebugrparamiko SSHClientclientset_missing_host_key_policy AutoAddPolicyconnectr open_sftpftprs rrzSFTPFileSystem._connect2su 3TYY?((*  //0F0F0HI DII99;;((*rct|dS)Npathr)clsr(s r_strip_protocolzSFTPFileSystem._strip_protocol9s$T*622rcdt|}|jdd|jdd|S)Nr(protocol)rr)urlpathouts r_get_kwargs_from_urlsz$SFTPFileSystem._get_kwargs_from_urls=s-#G,   D! rc|j|}tjd||j|rt d||r|j |y|j j||y)NzCreating folder %s File exists: )r*rrexistsFileExistsErrormakedirsr%mkdir)rr(create_parentsmodes rr5zSFTPFileSystem.mkdirDs`##D) )40 ;;t !M$"89 9  MM$  HHNN4 &rc|j|r|std||jd}|dddk(rdnd}|D]>}|s|r|d|n|}|j|r#|jj ||@y)Nr1/)r2r3splitr%r5)rr(exist_okr7partsnew_pathparts rr4zSFTPFileSystem.makedirsOs ;;t X!M$"89 9 3r(c/3r 3D3;hZq/{{8,HHNN8T2  3rc|j|}tjd||jj |y)NzRemoving folder %s)r*rrr%rmdirrr(s rrBzSFTPFileSystem.rmdir\s1##D) )40 trc|j|}|j|jj|}||d<|S)Nname)r* _decode_statr%stat)rr(rGs rinfozSFTPFileSystem.infoas=##D)  t!45V  rc  t|jrd}nt|jrd}nd}d|j||j|j t j j|jt jjt j j|jt jjd}|r/dj|jd|jg|d<|S) N directorylinkfiler;)tz)rEsizetypeuidgidtimemtimer9rE)rst_moderst_sizest_uidst_giddatetime fromtimestampst_atimetimezoneutcst_mtimejoinrstripfilename)rG parent_pathtr.s rrFzSFTPFileSystem._decode_statgs 4<< A T\\ "AALL;;;;%%33 ("3"3"7"74&&44 ("3"3"7"75   ((K$6$6s$;T]]#KLCK rc|j|}tjd||jj |Dcgc]}|j ||}}|r|S|Dcgc]}|d }}t |Scc}wcc}w)NzListing folder %srE)r*rrr% listdir_iterrFsorted)rr(detailrGstatspathss rlszSFTPFileSystem.lss##D) ($/;?88;P;PQU;VW4""4.WW L.34dT&\4E4%= X5s B( Bc |j|}tjd|||jj ||y)NzPut file %s into %s)r*rrr%put)rlpathrpathcallbackkwargss rrkzSFTPFileSystem.puts5$$U+ *E59  UE"rc |j|rtj|dy|jj |j ||y)NT)r=)isdirosr4r%getr*)rrmrlros rget_filezSFTPFileSystem.get_files9 ::e  KK - HHLL--e4e 1, buffer that many bytes, if None use default from paramiko. zOpening file %s autocommitTFr9)bufsize)rrrsr^rstruuiduuid4r%open targetpathfstypes MethodType commit_a_filecommitdiscard_a_filediscard)rr(r7 block_sizeropath2fs r_openzSFTPFileSystem._opens  &- ::lD )U 2HHdmmS->?@E eT:QS TAAJALAD'' q9AH((;AI dD *PR SArc|j|r|jj|y|jj|yN)rqr%rBremoverCs r_rmzSFTPFileSystem._rms. ::d  HHNN4 HHOOD !rc|j|}|j|}tjd|||jj ||y)NzRenaming %s into %s)r*rrr% posix_rename)roldnews rmvzSFTPFileSystem.mvsG""3'""3' *C5 c3'r)T)Frr)F)rbN)__name__ __module__ __qualname____doc__r,rr classmethodr* staticmethodr/r5r4rBrHrFrirkrtrrr __classcell__)rs@rr r sH,+33 ' 3  0!# = (" (rr cd|jj|j|jyr)r~rrr}r&s rrrsGGJJt}}doo.rcN|jj|jyr)r~rrr&s rrrsGGKK r)rXloggingrrrrzrGrrrr;rutilsr getLoggerrr rrrrrrsL !!)   = )c('c(L/r