U C^@sdddlZddlmZmZddlZddlZddlmZddlm Z GdddeZ dd Z d d Z dS) N)S_ISDIRS_ISLNK)AbstractFileSysteminfer_storage_optionscseZdZdZdZfddZddZeddZe d d Z d#d d Z d$ddZ ddZ ddZd%ddZddZddZd&ddZdd Zd!d"ZZS)'SFTPFileSystemzNFiles over SFTP/SSH Peer-to-peer filesystem over SSH using paramiko. )sftpsshc sB|jr dStt|jf||dd|_||_||_|dS)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 http://docs.paramiko.org/en/2.4/api/client.html#paramiko.client.SSHClient.connect May include port, username, password... Ntemppathz/tmp) _cachedsuperr__init__popr host ssh_kwargs_connect)selfrr __class__?/tmp/pip-install-6_kvzl1k/fsspec/fsspec/implementations/sftp.pyrszSFTPFileSystem.__init__cCs>t|_|jt|jj|jf|j|j|_ dSN) paramikoZ SSHClientclientZset_missing_host_key_policyZ AutoAddPolicyconnectrrZ open_sftpftprrrrr's zSFTPFileSystem._connectcCs t|dS)Npathr)clsrrrr_strip_protocol-szSFTPFileSystem._strip_protocolcCs$t|}|dd|dd|S)Nrprotocol)rr)Zurlpathoutrrr_get_kwargs_from_urls1s  z$SFTPFileSystem._get_kwargs_from_urlscCs|j||dSr)rmkdir)rrmoderrrr%8szSFTPFileSystem.mkdirFcCsZ||r|std||d}d}|D]&}|d|7}||s.|||q.dS)NzFile exists: {}/)existsFileExistsErrorformatsplitr%)rrexist_okr&partspartrrrmakedirs;s   zSFTPFileSystem.makedirscCs|j|dSr)rrmdirrrrrrr1GszSFTPFileSystem.rmdircCs^|j|}t|jrd}nt|jr,d}nd}|dkr@|dn||j||j|j|j|j dS)N directorylinkfiler')namesizetypeuidguitimemtime) rstatrst_moderst_sizest_uidst_gidst_atimest_mtime)rrstrrrinfoJs   zSFTPFileSystem.infocsFfddjD}fdd|D}|r4|Stdd|DS)Ncs g|]}dd|gqS)r')joinrstrip.0p)rrr ]sz%SFTPFileSystem.ls..csg|]}|qSr)rF)rJorrrrL^scSsg|] }|dqS)r6rrIrrrrLas)rlistdirsorted)rrZdetailr"r)rrrls\s zSFTPFileSystem.lscCs|j||dSr)rput)rlpathrpathrrrrQcszSFTPFileSystem.putcCs|j||dSr)rget)rrSrRrrrrTfszSFTPFileSystem.getrbNcKs|dddkrld|jt}|jj|||r4|ndd}||_||_||_t t ||_ t t ||_n|jj|||r~|ndd}|S)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 autocommitTFz{}/{})bufsize)rTr+r uuidZuuid4ropen targetpathfstypes MethodType commit_a_filecommitdiscard_a_filediscard)rrr& block_sizekwargspath2frrr_openiszSFTPFileSystem._opencCs(||r|j|n |j|dSr)isdirrr1remover2rrr_rm|s zSFTPFileSystem._rmcCs|j||dSr)rZ posix_rename)roldnewrrrmvszSFTPFileSystem.mv)r$)Fr$)F)rUN)__name__ __module__ __qualname____doc__r!rr classmethodr staticmethodr#r%r0r1rFrPrQrTrfrirl __classcell__rrrrr s$       rcCs|j|j|jdSr)r[rlr rZrrrrr^sr^cCs|j|jdSr)r[rir rrrrr`sr`) rr=rrr\rXr(rutilsrrr^r`rrrrs  }