Changeset 8852

Show
Ignore:
Timestamp:
09/09/08 03:24:05 (3 months ago)
Author:
azaozz
Message:

SSH2 filesystem improvements, props ShaneF, see #7690

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/includes/class-wp-filesystem-ssh2.php

    r8812 r8852  
    99/** 
    1010 * WordPress Filesystem Class for implementing SSH2. 
     11 * 
     12 * To use this class you must follow these steps for PHP 5.2.6+ 
     13 * 
     14 * @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes 
     15 * 
     16 * Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now.) 
     17 * 
     18 * cd /usr/src 
     19 * wget http://surfnet.dl.sourceforge.net/sourceforge/libssh2/libssh2-0.14.tar.gz 
     20 * tar -zxvf libssh2-0.14.tar.gz 
     21 * cd libssh2-0.14/ 
     22 * ./configure 
     23 * make all install 
     24 * 
     25 * Note: No not leave the directory yet! 
     26 * 
     27 * Enter: pecl install -f ssh2 
     28 * 
     29 * Copy the ssh.so file it creates to your PHP Module Directory. 
     30 * Open up your PHP.INI file and look for where extensions are placed. 
     31 * Add in your PHP.ini file: extension=ssh2.so 
     32 * 
     33 * Restart Apache! 
     34 * Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp  exist. 
     35 * 
    1136 * 
    1237 * @since 2.7 
     
    1641 */ 
    1742class WP_Filesystem_SSH2 extends WP_Filesystem_Base { 
    18      
    19     var $debugtest = true;  //  this is my var that will output the text when debuggin this class 
    20      
    21     var $link; 
    22     var $timeout = 5; 
     43 
     44    var $debugtest = false; //  this is my var that will output the text when debuggin this class 
     45 
     46    var $link = null; 
     47    var $sftp_link = null; 
     48    /* 
     49     * This is the timeout value for ssh results to comeback. 
     50     * Slower servers might need this incressed, but this number otherwise should not change. 
     51     * 
     52     * @parm $timeout int 
     53     * 
     54     */ 
     55    var $timeout = 15; 
    2356    var $errors = array(); 
    2457    var $options = array(); 
    2558 
    26     var $permission = null; 
    27  
    28     var $filetypes = array( 
    29                             'php'=>FTP_ASCII, 
    30                             'css'=>FTP_ASCII, 
    31                             'txt'=>FTP_ASCII, 
    32                             'js'=>FTP_ASCII, 
    33                             'html'=>FTP_ASCII, 
    34                             'htm'=>FTP_ASCII, 
    35                             'xml'=>FTP_ASCII, 
    36  
    37                             'jpg'=>FTP_BINARY, 
    38                             'png'=>FTP_BINARY, 
    39                             'gif'=>FTP_BINARY, 
    40                             'bmp'=>FTP_BINARY 
    41                             ); 
     59    var $permission = 0644; 
    4260 
    4361    function WP_Filesystem_SSH2($opt='') { 
     
    7290 
    7391        if ( empty ($opt['password']) ) 
    74             $this->errors->add('empty_password', __('SSH password is required')); 
     92            $this->errors->add('empty_password', __('SSH2 password is required')); 
    7593        else 
    7694            $this->options['password'] = $opt['password']; 
    77  
    7895    } 
    7996 
     
    92109        } 
    93110 
     111        $this->sftp_link = ssh2_sftp($this->link); 
     112 
    94113        return true; 
    95114    } 
    96      
     115 
    97116    function run_command($link, $command, $returnbool = false) { 
    98         $this->debug("run_command(".$command.");"); 
    99         if(!($stream = @ssh2_exec( $link, $command ))) { 
    100             $this->errors->add('command', sprintf(__('Unable to preform command: %s'), $command)); 
    101         } else { 
    102             stream_set_blocking( $stream, true ); 
     117        //$this->debug("run_command(".$command.",".$returnbool.");"); 
     118        if(!($stream = @ssh2_exec( $link, $command . "; echo \"__COMMAND_FINISHED__\";"))) { 
     119           $this->errors->add('command', sprintf(__('Unable to perform command: %s'), $command)); 
     120       } else { 
     121           stream_set_blocking( $stream, true ); 
    103122            $time_start = time(); 
    104             $data = ""
     123           $data = null
    105124            while( true ) { 
    106                 if( (time()-$time_start) > $this->timeout ){ 
    107                     $this->errors->add('command', sprintf(__('Connection to the server has timeout after %s seconds.'), $this->timeout)); 
    108                     break; 
    109                 } 
    110                 while( $buf = fread( $stream, strlen($stream) ) ){ 
    111                     $data .= $buf; 
    112                 } 
     125                if (strpos($data,"__COMMAND_FINISHED__") !== false){ 
     126                    break;  //  the command has finshed! 
     127                } 
     128                if( (time()-$time_start) > $this->timeout ){ 
     129                    $this->errors->add('command', sprintf(__('Connection to the server has timeout after %s seconds.'), $this->timeout)); 
     130                    unset($this->link); 
     131                    unset($this->sftp_link); // close connections 
     132                    return false; 
     133                } 
     134                while( $buf = fread( $stream, strlen($stream) ) ) 
     135                    $data .= $buf; 
    113136            } 
    114             fclose($stream); 
    115             if (($returnbool) && ($data)) { 
    116                 $this->debug("Data: " . print_r($data, true) . " Returning: True"); 
    117                 return true; 
    118             } elseif (($returnbool) && (!$data)) { 
    119                 $this->debug("Data: " . print_r($data, true) . " Returning: False"); 
    120                 return false; 
    121             } else { 
    122                 $this->debug("Data: " . print_r($data, true)); 
    123                 return $data; 
    124             } 
    125         } 
     137            fclose($stream); 
     138            $data = str_replace("__COMMAND_FINISHED__", "", $data); 
     139            //$this->debug("run_command(".$command."); --> \$data = " . $data); 
     140            if (($returnbool) && ( (int) $data )) { 
     141                $this->debug("Data. Returning: True"); 
     142                return true; 
     143            } elseif (($returnbool) && (! (int) $data )) { 
     144                $this->debug("Data. Returning: False"); 
     145                return false; 
     146            } else { 
     147                $this->debug("Data Only."); 
     148                return $data; 
     149            } 
     150        } 
     151        return false; 
    126152    } 
    127153 
     
    130156        if ($this->debugtest) 
    131157        { 
    132             echo $text . "<br/>"; 
     158            echo "<br/>" . $text . "<br/>"; 
    133159        } 
    134160    } 
    135161 
    136162    function setDefaultPermissions($perm) { 
    137         $this->permission = $perm; 
    138     } 
    139  
    140     function get_contents($file, $type = '', $resumepos = 0 ){ 
    141         if( empty($type) ){ 
    142             $extension = substr(strrchr($file, "."), 1); 
    143             $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; 
    144         } 
    145         $temp = tmpfile(); 
     163        $this->debug("setDefaultPermissions();"); 
     164        if ( $perm ) 
     165            $this->permission = $perm; 
     166    } 
     167 
     168    function get_contents($file, $type = '', $resumepos = 0 ) { 
     169        $tempfile = wp_tempnam( $file ); 
     170        if ( ! $tempfile ) 
     171            return false; 
     172        if( ! ssh2_scp_recv($this->link, $file, $tempfile) ) 
     173            return false; 
     174        $contents = file_get_contents($tempfile); 
     175        unlink($tempfile); 
     176        return $contents; 
     177    } 
     178 
     179    function get_contents_array($file) { 
     180        $this->debug("get_contents_array();"); 
     181        return explode("\n", $this->get_contents($file)); 
     182    } 
     183 
     184    function put_contents($file, $contents, $type = '' ) { 
     185        $tempfile = wp_tempnam( $file ); 
     186        $temp = fopen($tempfile, 'w'); 
    146187        if ( ! $temp ) 
    147188            return false; 
    148         if( ! @ssh2_scp_recv($this->link, $temp, $file) ) 
    149             return false; 
    150         fseek($temp, 0); //Skip back to the start of the file being written to 
    151         $contents = ''; 
    152         while (!feof($temp)) { 
    153             $contents .= fread($temp, 8192); 
    154         } 
     189        fwrite($temp, $contents); 
    155190        fclose($temp); 
    156         return $contents; 
    157     } 
    158      
    159     function get_contents_array($file) { 
    160         return explode("\n", $this->get_contents($file)); 
    161     } 
    162      
    163     function put_contents($file, $contents, $type = '' ) { 
    164         if( empty($type) ) { 
    165             $extension = substr(strrchr($file, "."), 1); 
    166             $type = isset($this->filetypes[ $extension ]) ? $this->filetypes[ $extension ] : FTP_ASCII; 
    167         } 
    168         $temp = tmpfile(); 
    169         if ( ! $temp ) 
    170             return false; 
    171         fwrite($temp, $contents); 
    172         fseek($temp, 0); //Skip back to the start of the file being written to 
    173         $ret = @ssh2_scp_send($this->link, $file, $temp, $type); 
    174         fclose($temp); 
     191        $ret = ssh2_scp_send($this->link, $tempfile, $file, $this->permission); 
     192        unlink($tempfile); 
    175193        return $ret; 
    176194    } 
    177      
     195 
    178196    function cwd() { 
    179         $cwd = $this->run_command($this->link, "pwd"); 
     197        $cwd = $this->run_command($this->link, 'pwd'); 
    180198        if( $cwd ) 
    181199            $cwd = trailingslashit($cwd); 
    182200        return $cwd; 
    183201    } 
    184      
     202 
    185203    function chdir($dir) { 
    186         if ($this->run_command($this->link, "cd " . $dir, true)) { 
    187             return true; 
    188         } 
    189         return false; 
    190     } 
    191      
     204        return $this->run_command($this->link, 'cd ' . $dir, true); 
     205    } 
     206 
    192207    function chgrp($file, $group, $recursive = false ) { 
    193         return false; 
    194     } 
    195      
     208        $this->debug("chgrp();"); 
     209        if ( ! $this->exists($file) ) 
     210            return false; 
     211        if ( ! $recursive || ! $this->is_dir($file) ) 
     212            return $this->run_command($this->link, sprintf('chgrp %o %s', $mode, $file), true); 
     213        return $this->run_command($this->link, sprintf('chgrp -R %o %s', $mode, $file), true); 
     214    } 
     215 
    196216    function chmod($file, $mode = false, $recursive = false) { 
     217        $this->debug("chmod();"); 
    197218        if( ! $mode ) 
    198219            $mode = $this->permission; 
     
    201222        if ( ! $this->exists($file) ) 
    202223            return false; 
    203         if ( ! $recursive || ! $this->is_dir($file) ) { 
    204             return $this->run_command($this->link, sprintf('CHMOD %o %s', $mode, $file), true); 
    205         } 
    206         //Is a directory, and we want recursive 
    207         $filelist = $this->dirlist($file); 
    208         foreach($filelist as $filename){ 
    209             $this->chmod($file . '/' . $filename, $mode, $recursive); 
    210         } 
    211         return true; 
    212     } 
    213      
     224        if ( ! $recursive || ! $this->is_dir($file) ) 
     225            return $this->run_command($this->link, sprintf('chmod %o %s', $mode, $file), true); 
     226        return $this->run_command($this->link, sprintf('chmod -R %o %s', $mode, $file), true); 
     227    } 
     228 
    214229    function chown($file, $owner, $recursive = false ) { 
    215         return false; 
    216     } 
    217      
     230        $this->debug("chown();"); 
     231        if ( ! $this->exists($file) ) 
     232            return false; 
     233        if ( ! $recursive || ! $this->is_dir($file) ) 
     234            return $this->run_command($this->link, sprintf('chown %o %s', $mode, $file), true); 
     235        return $this->run_command($this->link, sprintf('chown -R %o %s', $mode, $file), true); 
     236    } 
     237 
    218238    function owner($file) { 
     239        $this->debug("owner();"); 
    219240        $dir = $this->dirlist($file); 
    220241        return $dir[$file]['owner']; 
    221242    } 
    222      
     243 
    223244    function getchmod($file) { 
     245        $this->debug("getchmod();"); 
    224246        $dir = $this->dirlist($file); 
    225247        return $dir[$file]['permsn']; 
    226248    } 
    227      
     249 
    228250    function group($file) { 
     251        $this->debug("group();"); 
    229252        $dir = $this->dirlist($file); 
    230253        return $dir[$file]['group']; 
    231254    } 
    232      
     255 
    233256    function copy($source, $destination, $overwrite = false ) { 
     257        $this->debug("copy();"); 
    234258        if( ! $overwrite && $this->exists($destination) ) 
    235259            return false; 
     
    239263        return $this->put_contents($destination, $content); 
    240264    } 
    241      
     265 
    242266    function move($source, $destination, $overwrite = false) { 
     267        $this->debug("move();"); 
    243268        return @ssh2_sftp_rename($this->link, $source, $destination); 
    244269    } 
    245270 
    246     function delete($file, $recursive=false) { 
     271    function delete($file, $recursive = false) { 
    247272        if ( $this->is_file($file) ) 
    248             return @ssh2_sftp_unlink($this->link, $file); 
    249         if ( !$recursive ) 
    250             return @ssh2_sftp_rmdir($this->link, $file); 
     273            return ssh2_sftp_unlink($this->sftp_link, $file); 
     274        if ( ! $recursive ) 
     275            return ssh2_sftp_rmdir($this->sftp_link, $file); 
    251276        $filelist = $this->dirlist($file); 
    252         foreach ((array) $filelist as $filename => $fileinfo) { 
    253             $this->delete($file . '/' . $filename, $recursive); 
    254         } 
    255         return @ssh2_sftp_rmdir($this->link, $file); 
     277        if ( is_array($filelist) ) { 
     278            foreach ( $filelist as $filename => $fileinfo) { 
     279                $this->delete($file . '/' . $filename, $recursive); 
     280            } 
     281        } 
     282        return ssh2_sftp_rmdir($this->sftp_link, $file); 
    256283    } 
    257284 
    258285    function exists($file) { 
    259         $list = $this->run_command($this->link, sprintf('ls -la %s', $file)); 
    260         if( ! $list ) 
    261             return false; 
    262         return count($list) == 1 ? true : false; 
    263     } 
    264      
     286        $list = $this->run_command($this->link, sprintf('ls -lad %s', $file)); 
     287        return (bool) $list; 
     288    } 
     289 
    265290    function is_file($file) { 
    266         return $this->is_dir($file) ? false : true; 
    267     } 
    268      
     291        //DO NOT RELY ON dirlist()! 
     292        $list = $this->run_command($this->link, sprintf('ls -lad %s', $file)); 
     293        $list = $this->parselisting($list); 
     294        if ( ! $list ) 
     295            return false; 
     296        else 
     297            return ( !$list['isdir'] && !$list['islink'] ); //ie. not a file or link, yet exists, must be file. 
     298    } 
     299 
    269300    function is_dir($path) { 
    270         $cwd = $this->cwd(); 
    271         $result = $this->run_command($this->link, sprintf('cd %s', $path), true); 
    272         if( $result && $path == $this->cwd() || $this->cwd() != $cwd ) { 
    273             // @todo: use ssh2_exec 
    274             @ftp_chdir($this->link, $cwd); 
    275             return true; 
    276         } 
    277         return false; 
    278     } 
    279      
     301        //DO NOT RELY ON dirlist()! 
     302        $list = $this->parselisting($this->run_command($this->link, sprintf('ls -lad %s', rtrim($path, '/')))); 
     303        if ( ! $list ) 
     304            return false; 
     305        else 
     306            return $list['isdir']; 
     307    } 
     308 
    280309    function is_readable($file) { 
    281         //Get dir list, Check if the file is writable by the current user?? 
    282         return true; 
    283     } 
    284      
     310        //Not implmented. 
     311    } 
     312 
    285313    function is_writable($file) { 
    286         //Get dir list, Check if the file is writable by the current user?? 
    287         return true; 
    288     } 
    289      
     314        //Not implmented. 
     315    } 
     316 
    290317    function atime($file) { 
    291         return false; 
    292     } 
    293      
     318        //Not implmented. 
     319    } 
     320 
    294321    function mtime($file) { 
    295         return; //  i have to look up to see if there is a way in SSH2 to look the modifed date 
    296         //  return ftp_mdtm($this->link, $file); 
    297     } 
    298      
     322        //Not implmented. 
     323    } 
     324 
    299325    function size($file) { 
    300         return; //  i have to look up to see if there is a way in SSH2 to get the file size 
    301         //  return ftp_size($this->link, $file); 
    302     } 
    303      
     326        //Not implmented. 
     327    } 
     328 
    304329    function touch($file, $time = 0, $atime = 0) { 
    305         return false; 
    306     } 
    307      
    308     function mkdir($path, $chmod = false, $chown = false, $chgrp = false) { 
    309         if( !@ssh2_sftp_mkdir($this->link, $path) ) 
    310             return false; 
    311         if( $chmod ) 
    312             $this->chmod($path, $chmod); 
     330        //Not implmented. 
     331    } 
     332 
     333    function mkdir($path, $chmod = null, $chown = false, $chgrp = false) { 
     334        if( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) ) 
     335            return false; 
    313336        if( $chown ) 
    314337            $this->chown($path, $chown); 
     
    317340        return true; 
    318341    } 
    319      
     342 
    320343    function rmdir($path, $recursive = false) { 
    321         if( ! $recursive ) 
    322             return @ssh2_sftp_rmdir($this->link, $path); 
    323  
    324         //TODO: Recursive Directory delete, Have to delete files from the folder first. 
    325         //$dir = $this->dirlist($path); 
    326         //foreach($dir as $file) 
    327  
     344        return $this->delete($path, $recursive); 
    328345    } 
    329346 
    330347    function parselisting($line) { 
     348    $this->debug("parselisting();"); 
    331349        $is_windows = ($this->OS_remote == FTP_OS_Windows); 
    332350        if ($is_windows && preg_match("/([0-9]{2})-([0-9]{2})-([0-9]{2}) +([0-9]{2}):([0-9]{2})(AM|PM) +([0-9]+|<DIR>) +(.+)/", $line, $lucifer)) { 
     
    391409 
    392410    function dirlist($path = '.', $incdot = false, $recursive = false) { 
     411        $this->debug("dirlist();"); 
    393412        if( $this->is_file($path) ) { 
    394413            $limitFile = basename($path); 
    395             $path = dirname($path) . '/'
     414            $path = trailingslashit(dirname($path))
    396415        } else { 
    397416            $limitFile = false; 
    398417        } 
    399          
    400         $list = $this->run_command($this->link, sprintf('ls -a %s', $path)); 
     418 
     419        $list = $this->run_command($this->link, sprintf('ls -la %s', $path)); 
    401420 
    402421        if ( $list === false ) 
    403422            return false; 
    404423 
     424        $list = explode("\n", $list); 
     425 
    405426        $dirlist = array(); 
    406         foreach ( $list as $k => $v ) { 
     427        foreach ( (array)$list as $k => $v ) { 
    407428            $entry = $this->parselisting($v); 
    408429            if ( empty($entry) ) 
    409430                continue; 
    410431 
    411             if ( '.' == $entry["name"] || '..' == $entry["name"] ) 
     432            if ( '.' == $entry['name'] || '..' == $entry['name'] ) 
    412433                continue; 
    413434 
     
    417438        if ( ! $dirlist ) 
    418439            return false; 
     440 
    419441        if ( empty($dirlist) ) 
    420442            return array(); 
     
    433455                    } 
    434456                } else { //No dots 
    435                     if ($recursive
     457                    if ( $recursive
    436458                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive); 
    437459                } 
     
    444466 
    445467    function __destruct(){ 
    446         if( $this->link ) 
     468        if ( $this->link ) 
    447469            unset($this->link); 
     470        if ( $this->sftp_link ) 
     471            unset($this->sftp_link); 
    448472    } 
    449473} 
  • trunk/wp-admin/includes/file.php

    r8811 r8852  
    387387        return new WP_Error('empty_archive', __('Empty archive')); 
    388388 
     389    $path = explode('/', $to); 
     390    for ( $i = count($path); $i > 0; $i-- ) { //>0 = first element is empty allways for paths starting with '/' 
     391        $tmppath = implode('/', array_slice($path, 0, $i) ); 
     392        if ( $fs->is_dir($tmppath) ) { //Found the highest folder that exists, Create from here(ie +1) 
     393            for ( $i = $i + 1; $i <= count($path); $i++ ) { 
     394                $tmppath = implode('/', array_slice($path, 0, $i) ); 
     395                if ( ! $fs->mkdir($tmppath, 0755) ) 
     396                    return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath); 
     397            } 
     398            break; //Exit main for loop 
     399        } 
     400    } 
     401 
    389402    $to = trailingslashit($to); 
    390     $path = explode('/', $to); 
    391     $tmppath = ''; 
    392     for ( $j = 0; $j < count($path) - 1; $j++ ) { 
    393         $tmppath .= $path[$j] . '/'; 
    394         if ( ! $fs->is_dir($tmppath) ) 
    395             $fs->mkdir($tmppath, 0755); 
    396     } 
    397  
    398403    foreach ($archive_files as $file) { 
    399404        $path = explode('/', $file['filename']); 
    400         $tmppath = ''; 
    401  
    402         // Loop through each of the items and check that the folder exists. 
    403         for ( $j = 0; $j < count($path) - 1; $j++ ) { 
    404             $tmppath .= $path[$j] . '/'; 
    405             if ( ! $fs->is_dir($to . $tmppath) ) 
    406                 if ( !$fs->mkdir($to . $tmppath, 0755) ) 
    407                     return new WP_Error('mkdir_failed', __('Could not create directory'), $to . $tmppath); 
     405        for ( $i = count($path) - 1; $i >= 0; $i-- ) { //>=0 as the first element contains data, count()-1, as we do not want the file component 
     406            $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 
     407            if ( $fs->is_dir($tmppath) ) {//Found the highest folder that exists, Create from here 
     408                for ( $i = $i + 1; $i < count($path); $i++ ) { //< count() no file component please. 
     409                    $tmppath = $to . implode('/', array_slice($path, 0, $i) ); 
     410                    if ( ! $fs->mkdir($tmppath, 0755) ) 
     411                        return new WP_Error('mkdir_failed', __('Could not create directory'), $tmppath); 
     412                } 
     413                break; //Exit main for loop 
     414            } 
    408415        } 
    409416 
     
    415422        } 
    416423    } 
    417  
    418424    return true; 
    419425} 
     
    454460        return false; 
    455461 
    456     $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method); 
     462    $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method); 
    457463    if( ! file_exists($abstraction_file) ) 
    458464        return; 
     
    481487    } 
    482488 
    483     if ( isset($args['connection_type']) && 'ssh' == $args['connection_type'] ) { 
    484         $method = 'SSH2'; 
    485         return apply_filters('filesystem_method', $method); 
    486     } 
    487  
     489    if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') ) $method = 'ssh2'; 
    488490    if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext'; 
    489491    if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread 
     
    508510    $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? $_POST['username'] : $credentials['username']); 
    509511    $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? $_POST['password'] : $credentials['password']); 
    510     if ( defined('FTP_SSH') || 'ssh' == $_POST['connection_type'] ) 
     512     
     513    if ( strpos($credentials['hostname'], ':') ) 
     514        list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2); 
     515 
     516    if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) ) 
    511517        $credentials['connection_type'] = 'ssh'; 
    512     else if ( defined('FTP_SSL') || 'ftps' == $_POST['connection_type']
     518    else if ( defined('FTP_SSL') || (isset($_POST['connection_type']) && 'ftps' == $_POST['connection_type'])
    513519        $credentials['connection_type'] = 'ftps'; 
    514520    else 
     
    524530    $username = ''; 
    525531    $password = ''; 
    526     $ssl = ''; 
     532    $connection_type = ''; 
    527533    if ( !empty($credentials) ) 
    528534        extract($credentials, EXTR_OVERWRITE); 
     
    541547<tr valign="top"> 
    542548<th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th> 
    543 <td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname) ?>"<?php if( defined('FTP_HOST') ) echo ' disabled="disabled"' ?> size="40" /></td> 
     549<td><input name="hostname" type="text" id="hostname" value="<?php echo attribute_escape($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php if( defined('FTP_HOST') ) echo ' disabled="disabled"' ?> size="40" /></td> 
    544550</tr> 
    545551<tr valign="top"> 
     
    557563<p><label><input name="connection_type"  type="radio" value="ftp" <?php checked('ftp', $connection_type); ?>    /> <?php _e('FTP') ?></label><br /> 
    558564<label><input name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); ?> /> <?php _e('FTPS (SSL)') ?></label><br /> 
    559 <label><input name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label></p> 
     565<?php if ( extension_loaded('ssh2') ) { ?><label><input name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); ?> /> <?php _e('SSH') ?></label><?php } ?></p> 
    560566</fieldset> 
    561567</td> 
  • trunk/wp-admin/includes/update.php

    r8691 r8852  
    239239 
    240240    $working_dir = $content_dir . 'upgrade/core'; 
    241  
    242241    // Clean up working directory 
    243     if ( $wp_filesystem->is_dir($working_dir) ) 
    244         $wp_filesystem->delete($working_dir, true); 
    245  
    246     apply_filters('update_feedback', __('Unpacking the update')); 
     242    if ( $wp_filesystem->is_dir($working_dir) ) { 
     243        $wp_filesystem->delete($working_dir, true); 
     244    } 
     245 
     246    apply_filters('update_feedback', __('Unpacking the core update')); 
    247247    // Unzip package to working directory 
    248248    $result = unzip_file($download_file, $working_dir); 
    249  
    250249    // Once extracted, delete the package 
    251250    unlink($download_file); 
    252  
     251     
    253252    if ( is_wp_error($result) ) { 
    254253        $wp_filesystem->delete($working_dir, true); 
    255254        return $result; 
    256255    } 
    257  
     256     
    258257    // Copy update-core.php from the new version into place. 
    259258    if ( !$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true) ) {