Changeset 2412


Ignore:
Timestamp:
3/8/2012 7:06:32 AM (3 years ago)
Author:
lowjoel
Message:

Implemented alternative implementation for sftp's delete command.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/BuildUtil.php

    r2403 r2412  
    7373 
    7474    if (curl_exec($curl) === false) 
    75         throw new Exception('cURL Error: ' . curl_error($curl)); 
     75    { 
     76        $scheme = parse_url($url, PHP_URL_SCHEME); 
     77        if (curl_errno($curl) == CURLE_UNSUPPORTED_PROTOCOL && $scheme == 'sftp') 
     78            return Delete_Sftp($url, $username, $password); 
     79         
     80        throw new Exception('cURL Error ' . $scheme.curl_errno($curl) . ': '. curl_error($curl)); 
     81    } 
    7682    fclose($stream); 
    7783    curl_close($curl); 
     
    7985    printf("File deleted.\n"); 
    8086} 
     87 
     88function Delete_Sftp($url, $username = '', $password = '') 
     89{ 
     90    echo 'Trying alternative method... '; 
     91    $urlInfo = parse_url($url); 
     92     
     93    //Connect to the server and authenticate the server. 
     94    $ssh2 = ssh2_connect($urlInfo['host'], $urlInfo['port']); 
     95    $knownFingerprints = array( 
     96        'b0a8eb30ce1a0e6a4d7a6b3a0ac62760' 
     97    ); 
     98    if (!in_array($knownFingerprints, ssh2_fingerprint($ssh2, SSH2_FINGERPRINT_SHA1 | SSH2_FINGERPRINT_HEX))) 
     99    { 
     100        throw new Exception(sprintf('Authentication Error: The fingerprint provided ' . 
     101            'by %s is not recognised, disconnecting.', $urlInfo['host'])); 
     102    } 
     103     
     104    //Authenticate ourselves 
     105    if (!ssh2_auth_password($ssh2, $username, $password)) 
     106    { 
     107        throw new Exception('Authentication Error: The credentials provided are incorrect.'); 
     108    } 
     109     
     110    //Delete the file 
     111    $sftp = ssh2_sftp($ssh2); 
     112    if (!ssh2_sftp_unlink($sftp, $urlInfo['path'])) 
     113    { 
     114        throw new Exception(sprintf('SFTP Error: Could not delete file %s.', $urlInfo['path'])); 
     115    } 
     116     
     117    printf("File deleted.\n"); 
     118} 
    81119?> 
Note: See TracChangeset for help on using the changeset viewer.