Changeset 11633
- Timestamp:
- 06/23/2009 09:55:22 PM (15 years ago)
- Location:
- branches/2.8/wp-admin/includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.8/wp-admin/includes/class-wp-filesystem-ssh2.php
r11563 r11633 14 14 * @contrib http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/ - Installation Notes 15 15 * 16 * Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now .)16 * Complie libssh2 (Note: Only 0.14 is officaly working with PHP 5.2.6+ right now, But many users have found the latest versions work) 17 17 * 18 18 * cd /usr/src … … 23 23 * make all install 24 24 * 25 * Note: No not leave the directory yet!25 * Note: Do not leave the directory yet! 26 26 * 27 27 * Enter: pecl install -f ssh2 … … 34 34 * Check phpinfo() streams to confirm that: ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp exist. 35 35 * 36 * Note: as of WordPress 2.8, This utilises the PHP5+ function 'stream_get_contents' 36 37 * 37 38 * @since 2.7 … … 46 47 var $keys = false; 47 48 /* 48 * This is the timeout value for ssh results to comeback.49 * This is the timeout value for ssh results. 49 50 * Slower servers might need this incressed, but this number otherwise should not change. 50 51 * … … 67 68 return false; 68 69 } 69 if ( ! version_compare(phpversion(), '5', '>=') ) {70 $this->errors->add('ssh2_php_requirement', __('The ssh2 PHP extension is available, however requires PHP 5+'));70 if ( !function_exists('stream_get_contents') ) { 71 $this->errors->add('ssh2_php_requirement', __('The ssh2 PHP extension is available, however, we require the PHP5 function <code>stream_get_contents()</code>')); 71 72 return false; 72 73 } … … 102 103 103 104 if ( empty ($opt['password']) ) { 104 if ( !$this->keys ) // 105 if ( !$this->keys ) //password can be blank if we are using keys 105 106 $this->errors->add('empty_password', __('SSH2 password is required')); 106 107 } else { … … 149 150 stream_set_blocking( $stream, true ); 150 151 stream_set_timeout( $stream, $this->timeout ); 151 $data = stream_get_contents($stream); 152 $data = stream_get_contents( $stream ); 153 fclose( $stream ); 152 154 153 155 if ( $returnbool ) 154 return '' != trim($data);156 return ( $data === false ) ? false : '' != trim($data); 155 157 else 156 158 return $data; … … 167 169 function get_contents($file, $type = '', $resumepos = 0 ) { 168 170 $file = ltrim($file, '/'); 169 return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file);171 return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file); 170 172 } 171 173 172 174 function get_contents_array($file) { 173 175 $file = ltrim($file, '/'); 174 return file('ssh2.sftp://' . $this->sftp_link . '/' . $file);176 return file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 175 177 } 176 178 177 179 function put_contents($file, $contents, $type = '' ) { 178 180 $file = ltrim($file, '/'); 179 return file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);181 return file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents); 180 182 } 181 183 … … 271 273 272 274 function exists($file) { 273 //return $this->run_command(sprintf('ls -lad %s', escapeshellarg($file)), true); 274 $file = ltrim($file, '/'); 275 return file_exists('ssh2.sftp://' . $this->sftp_link .'/' . $file); 275 $file = ltrim($file, '/'); 276 return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file); 276 277 } 277 278 278 279 function is_file($file) { 279 280 $file = ltrim($file, '/'); 280 return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file);281 return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file); 281 282 } 282 283 283 284 function is_dir($path) { 284 285 $path = ltrim($path, '/'); 285 return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path);286 return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path); 286 287 } 287 288 288 289 function is_readable($file) { 289 290 $file = ltrim($file, '/'); 290 return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file);291 return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 291 292 } 292 293 293 294 function is_writable($file) { 294 295 $file = ltrim($file, '/'); 295 return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file);296 return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file); 296 297 } 297 298 298 299 function atime($file) { 299 300 $file = ltrim($file, '/'); 300 return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file);301 return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file); 301 302 } 302 303 303 304 function mtime($file) { 304 305 $file = ltrim($file, '/'); 305 return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file);306 return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file); 306 307 } 307 308 308 309 function size($file) { 309 310 $file = ltrim($file, '/'); 310 return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file);311 return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file); 311 312 } 312 313 -
branches/2.8/wp-admin/includes/file.php
r11588 r11633 646 646 } 647 647 648 if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && extension_loaded('sockets') ) $method = 'ssh2';648 if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2'; 649 649 if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext'; 650 650 if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread … … 762 762 </tr> 763 763 764 <?php if ( extension_loaded('ssh2') ) : ?>764 <?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?> 765 765 <tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>"> 766 766 <th scope="row"><?php _e('Authentication Keys') ?> … … 782 782 <br /><label><input id="ftps" name="connection_type" type="radio" value="ftps" <?php checked('ftps', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('FTPS (SSL)') ?></label> 783 783 <?php endif; ?> 784 <?php if ( extension_loaded('ssh2') ) : ?>784 <?php if ( extension_loaded('ssh2') && function_exists('stream_get_contents') ) : ?> 785 785 <br /><label><input id="ssh" name="connection_type" type="radio" value="ssh" <?php checked('ssh', $connection_type); if ( defined('FTP_SSL') || defined('FTP_SSH') ) echo ' disabled="disabled"'; ?>/> <?php _e('SSH') ?></label> 786 786 <?php endif; ?>
Note: See TracChangeset
for help on using the changeset viewer.