~katiekitty/+junk/wordpress-byet

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-filesystem-ssh2.php

  • Committer: kserver
  • Date: 2010-05-15 01:16:36 UTC
  • Revision ID: kserver@kserver-desktop-20100515011636-mnr1j7t637suptdq
Wordpress 2.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        var $link = false;
46
46
        var $sftp_link = false;
47
47
        var $keys = false;
48
 
        /*
49
 
         * This is the timeout value for ssh results.
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;
56
48
        var $errors = array();
57
49
        var $options = array();
58
50
 
59
 
        var $permission = 0644;
60
 
 
61
51
        function WP_Filesystem_SSH2($opt='') {
62
52
                $this->method = 'ssh2';
63
53
                $this->errors = new WP_Error();
148
138
                        $this->errors->add('command', sprintf(__('Unable to perform command: %s'), $command));
149
139
                } else {
150
140
                        stream_set_blocking( $stream, true );
151
 
                        stream_set_timeout( $stream, $this->timeout );
 
141
                        stream_set_timeout( $stream, FS_TIMEOUT );
152
142
                        $data = stream_get_contents( $stream );
153
143
                        fclose( $stream );
154
144
 
160
150
                return false;
161
151
        }
162
152
 
163
 
        function setDefaultPermissions($perm) {
164
 
                $this->debug("setDefaultPermissions();");
165
 
                if ( $perm )
166
 
                        $this->permission = $perm;
167
 
        }
168
 
 
169
153
        function get_contents($file, $type = '', $resumepos = 0 ) {
170
154
                $file = ltrim($file, '/');
171
155
                return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file);
178
162
 
179
163
        function put_contents($file, $contents, $type = '' ) {
180
164
                $file = ltrim($file, '/');
181
 
                return file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
 
165
                return false !== file_put_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file, $contents);
182
166
        }
183
167
 
184
168
        function cwd() {
201
185
        }
202
186
 
203
187
        function chmod($file, $mode = false, $recursive = false) {
204
 
                if( ! $mode )
205
 
                        $mode = $this->permission;
206
 
                if( ! $mode )
207
 
                        return false;
208
188
                if ( ! $this->exists($file) )
209
189
                        return false;
 
190
 
 
191
                if ( ! $mode ) {
 
192
                        if ( $this->is_file($file) )
 
193
                                $mode = FS_CHMOD_FILE;
 
194
                        elseif ( $this->is_dir($file) )
 
195
                                $mode = FS_CHMOD_DIR;
 
196
                        else
 
197
                                return false;
 
198
                }
 
199
 
210
200
                if ( ! $recursive || ! $this->is_dir($file) )
211
201
                        return $this->run_command(sprintf('chmod %o %s', $mode, escapeshellarg($file)), true);
212
202
                return $this->run_command(sprintf('chmod -R %o %s', $mode, escapeshellarg($file)), true);
315
305
                //Not implmented.
316
306
        }
317
307
 
318
 
        function mkdir($path, $chmod = null, $chown = false, $chgrp = false) {
 
308
        function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
319
309
                $path = untrailingslashit($path);
320
 
                $chmod = !empty($chmod) ? $chmod : $this->permission;
 
310
                if ( ! $chmod )
 
311
                        $chmod = FS_CHMOD_DIR;
321
312
                if ( ! ssh2_sftp_mkdir($this->sftp_link, $path, $chmod, true) )
322
313
                        return false;
323
314
                if ( $chown )
331
322
                return $this->delete($path, $recursive);
332
323
        }
333
324
 
334
 
        function dirlist($path, $incdot = false, $recursive = false) {
 
325
        function dirlist($path, $include_hidden = true, $recursive = false) {
335
326
                if ( $this->is_file($path) ) {
336
 
                        $limitFile = basename($path);
 
327
                        $limit_file = basename($path);
337
328
                        $path = dirname($path);
338
329
                } else {
339
 
                        $limitFile = false;
 
330
                        $limit_file = false;
340
331
                }
 
332
 
341
333
                if ( ! $this->is_dir($path) )
342
334
                        return false;
343
335
 
344
336
                $ret = array();
345
337
                $dir = @dir('ssh2.sftp://' . $this->sftp_link .'/' . ltrim($path, '/') );
 
338
 
346
339
                if ( ! $dir )
347
340
                        return false;
 
341
 
348
342
                while (false !== ($entry = $dir->read()) ) {
349
343
                        $struc = array();
350
344
                        $struc['name'] = $entry;
351
345
 
352
346
                        if ( '.' == $struc['name'] || '..' == $struc['name'] )
353
347
                                continue; //Do not care about these folders.
354
 
                        if ( '.' == $struc['name'][0] && !$incdot)
 
348
 
 
349
                        if ( ! $include_hidden && '.' == $struc['name'][0] )
355
350
                                continue;
356
 
                        if ( $limitFile && $struc['name'] != $limitFile)
 
351
 
 
352
                        if ( $limit_file && $struc['name'] != $limit_file )
357
353
                                continue;
358
354
 
359
355
                        $struc['perms']         = $this->gethchmod($path.'/'.$entry);
369
365
 
370
366
                        if ( 'd' == $struc['type'] ) {
371
367
                                if ( $recursive )
372
 
                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $incdot, $recursive);
 
368
                                        $struc['files'] = $this->dirlist($path . '/' . $struc['name'], $include_hidden, $recursive);
373
369
                                else
374
370
                                        $struc['files'] = array();
375
371
                        }