o zVa3@sddlmZddlmZeddlmZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddlZ Gd d d e jjZe jd ee jd ee jjd d gdS) )division)standard_library)mapN)config)log)util)BackendExceptionc@speZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZdS)SSHPExpectBackendz{This backend copies files using scp. List not supported. Filenames should not need any quoting or this will break.cCs6tjj||zddlaWntywd|_d|_tjr$tj|_d|_ tj r.tj |_ tj |j d|_ |j dk|_ |j rJ|j d|j|_n|j|_|jr\tdd |jd |_nd |_|jd |_|jrqtjd |jt_dtjvrtjdttjd7_dtjvrtjd7_tj|_||_dS)zscpBackend initializerrN scpsftppexpect@z^/./z -oPort=%sServerAliveIntervalz -oServerAliveInterval=%dServerAliveCountMaxz -oServerAliveCountMax=2) duplicitybackendBackend__init__r ImportError retry_delay scp_commandr sftp_command strip_prefixschemeuse_scpusernamehostname host_stringpathresub remote_dir remote_prefixport ssh_optionsinttimeout ssh_askpass use_getpass get_passwordpassword)self parsed_urlr3H/usr/lib/python3/dist-packages/duplicity/backends/ssh_pexpect_backend.pyr-s<      zSSHPExpectBackend.__init__cCstd|tj|dd}tjrd}nd} |dkrh|tjddd d g}td ||j f|d krRemote host authentication failed (missing known_hosts entry?)stalledETATimeout waiting for responsez"Stalled for too long, aborted copyTforcezError running '%s')rInfor spawnrr-expectEOFDebugbeforestripWarnsendliner0close exitstatusr)r1 commandlinechildstatematchr3r3r4run_scp_command^s         4  z!SSHPExpectBackend.run_scp_commandc Csd}tjdddddddd d g }td d |d dD}td|tj|d|tjd}d}d} d} |j|||d} t d|j | dkrLn| d krSd} n| dkr~|t |krs||} td| f| | |d 7}nsd} | | |j } nh| dkr|d 7}| |j|d krtdnQ| dkr|j dsd} nCnA| dkrd} n;| d kr|j d!sd"|f} n)n'| d#kr|j d$sd%|f} nn| d&krd%|f} n | d'krd(|f} nq2|jd)d*|jdkr| Std+|| f),zQ Run an sftp command, responding to password prompts, passing commands from list ir8zsftp>r9r:r;z(?i)no such file or directoryz/Couldn't delete file: No such file or directoryzCouldn't delete filezopen(.*): FailurecSsg|]}t|qSr3)len).0pr3r3r4 z6SSHPExpectBackend.run_sftp_command..rNr5)r,maxreadencodingrr)searchwindowsizezState = sftp, Before = '%s'r@rzsftp command: '%s'quitr<zInvalid SSH password.r=mkdirzPermission deniedzHHost key authenticity could not be verified (missing known_hosts entry?)rmz7Remote file or directory does not exist in command='%s'Removingz%Could not delete file in command='%s' z#Could not open file in command='%s'TrAzError running '%s': %s)r rFmaxrrCrDr fsencodingrErGrHrIrSrKr0r startswithrLrM) r1rNcommandsrX responsesmax_response_lenrOcmdloc passpromptmsgrQcommandresr3r3r4run_sftp_commands           . z"SSHPExpectBackend.run_sftp_commandcCs0t|}|jr|||dS|||dSN)rfsdecoder put_scpput_sftp)r1 source_pathremote_filenamer3r3r4_put zSSHPExpectBackend._putcCsJd|j|j|fd|j||j|fg}d|jtj|jf}|||dS)Nzput "%s" "%s.%s.part"zrename "%s.%s.part" "%s%s"%s %s %s)uc_namer(rrr*r#ro)r1rtrurgrNr3r3r4rss zSSHPExpectBackend.put_sftpcCs,d|jtj|j|j|j|f}||dS)Nz%s %s %s %s:%s%s)rrr*ryr#r(rR)r1rtrurNr3r3r4rr zSSHPExpectBackend.put_scpcCs0t|}|jr|||dS|||dSrp)rrqr get_scpget_sftp)r1ru local_pathr3r3r4_getrwzSSHPExpectBackend._getcCs8d|j||jfg}d|jtj|jf}|||dS)Nzget "%s%s" "%s"rx)r(ryrrr*r#ro)r1rur}rgrNr3r3r4r|s zSSHPExpectBackend.get_sftpcCs,d|jtj|j|j||jf}||dS)Nz%s %s %s:%s%s %s)rrr*r#r(ryrR)r1rur}rNr3r3r4r{ rzzSSHPExpectBackend.get_scpcCs|jtj}t|dkr|ddkrd|d<g}|D]}|d|gd|g7}q|dg}d|jtj|jf}| ||dd d}d d t dj j |DS) Nrrrz mkdir "%s"cd "%s"zls -1rx rcSsg|]}|r|qSr3r3)rTxr3r3r4rV#rWz+SSHPExpectBackend._list..) r'splitosseprSrrr*r#ror __class__rI)r1dirsmkdir_commandsdrgrNlr3r3r4_lists   zSSHPExpectBackend._listcCsFd|jfg}|dt|d|jtj|jf}|||dSNrzrm "%s"rx r'appendrrqrrr*r#ro)r1filenamergrNr3r3r4_delete%szSSHPExpectBackend._deletecCsPd|jfg}|D] }|dt|q d|jtj|jf}|||dSrr)r1 filename_listrgrrNr3r3r4 _delete_list+s zSSHPExpectBackend._delete_listN)__name__ __module__ __qualname____doc__rrRrorvrsrrr~r|r{rrrr3r3r3r4r *s1@F  r z pexpect+sftpz pexpect+scp) __future__rfuturerinstall_aliasesbuiltinsrrr%rrrrduplicity.errorsrduplicity.backendrrr register_backend uses_netlocextendr3r3r3r4s"