~canonical-sysadmins/wordpress/4.1.3

« back to all changes in this revision

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

  • Committer: Nick Moffitt
  • Date: 2015-01-15 11:05:37 UTC
  • mfrom: (1.1.1 wp4-upstream)
  • Revision ID: nick.moffitt@canonical.com-20150115110537-8bp1y42eyg0jsa7c
Tags: 4.1
MergeĀ upstreamĀ versionĀ 4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
                return true;
124
124
        }
125
125
 
 
126
        /**
 
127
         * @param string $command
 
128
         * @param bool $returnbool
 
129
         */
126
130
        public function run_command( $command, $returnbool = false) {
127
131
 
128
132
                if ( ! $this->link )
144
148
                return false;
145
149
        }
146
150
 
 
151
        /**
 
152
         * @param string $file
 
153
         * @return string|false
 
154
         */
147
155
        public function get_contents( $file ) {
148
156
                $file = ltrim($file, '/');
149
157
                return file_get_contents('ssh2.sftp://' . $this->sftp_link . '/' . $file);
150
158
        }
151
159
 
 
160
        /**
 
161
         * @param string $file
 
162
         * @return array
 
163
         */
152
164
        public function get_contents_array($file) {
153
165
                $file = ltrim($file, '/');
154
166
                return file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
155
167
        }
156
168
 
 
169
        /**
 
170
         * @param string $file
 
171
         * @param string $contents
 
172
         * @param bool|int $mode
 
173
         * @return bool
 
174
         */
157
175
        public function put_contents($file, $contents, $mode = false ) {
158
176
                $ret = file_put_contents( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ), $contents );
159
177
 
172
190
                return $cwd;
173
191
        }
174
192
 
 
193
        /**
 
194
         * @param string $dir
 
195
         * @return bool
 
196
         */
175
197
        public function chdir($dir) {
176
198
                return $this->run_command('cd ' . $dir, true);
177
199
        }
178
200
 
 
201
        /**
 
202
         * @param string $file
 
203
         * @param string $group
 
204
         * @param bool $recursive
 
205
         */
179
206
        public function chgrp($file, $group, $recursive = false ) {
180
207
                if ( ! $this->exists($file) )
181
208
                        return false;
184
211
                return $this->run_command(sprintf('chgrp -R %s %s', escapeshellarg($group), escapeshellarg($file)), true);
185
212
        }
186
213
 
 
214
        /**
 
215
         * @param string $file
 
216
         * @param int $mode
 
217
         * @param bool $recursive
 
218
         * @return bool
 
219
         */
187
220
        public function chmod($file, $mode = false, $recursive = false) {
188
221
                if ( ! $this->exists($file) )
189
222
                        return false;
207
240
         *
208
241
         * @since Unknown
209
242
         *
210
 
         * @param string $file    Path to the file.
211
 
         * @param mixed  $owner   A user name or number.
212
 
         * @param bool $recursive Optional. If set True changes file owner recursivly. Defaults to False.
213
 
         * @return bool Returns true on success or false on failure.
 
243
         * @param string     $file    Path to the file.
 
244
         * @param string|int $owner   A user name or number.
 
245
         * @param bool       $recursive Optional. If set True changes file owner recursivly. Defaults to False.
 
246
         * @return bool|string Returns true on success or false on failure.
214
247
         */
215
248
        public function chown( $file, $owner, $recursive = false ) {
216
249
                if ( ! $this->exists($file) )
220
253
                return $this->run_command(sprintf('chown -R %s %s', escapeshellarg($owner), escapeshellarg($file)), true);
221
254
        }
222
255
 
 
256
        /**
 
257
         * @param string $file
 
258
         * @return string|false
 
259
         */
223
260
        public function owner($file) {
224
261
                $owneruid = @fileowner('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));
225
262
                if ( ! $owneruid )
229
266
                $ownerarray = posix_getpwuid($owneruid);
230
267
                return $ownerarray['name'];
231
268
        }
232
 
 
 
269
        /**
 
270
         * @param string $file
 
271
         * @return string
 
272
         */
233
273
        public function getchmod($file) {
234
274
                return substr( decoct( @fileperms( 'ssh2.sftp://' . $this->sftp_link . '/' . ltrim( $file, '/' ) ) ), -3 );
235
275
        }
236
276
 
 
277
        /**
 
278
         * @param string $file
 
279
         * @return string|false
 
280
         */
237
281
        public function group($file) {
238
282
                $gid = @filegroup('ssh2.sftp://' . $this->sftp_link . '/' . ltrim($file, '/'));
239
283
                if ( ! $gid )
244
288
                return $grouparray['name'];
245
289
        }
246
290
 
 
291
        /**
 
292
         * @param string $source
 
293
         * @param string $destination
 
294
         * @param bool $overwrite
 
295
         * @param int|bool $mode
 
296
         * @return bool
 
297
         */
247
298
        public function copy($source, $destination, $overwrite = false, $mode = false) {
248
299
                if ( ! $overwrite && $this->exists($destination) )
249
300
                        return false;
253
304
                return $this->put_contents($destination, $content, $mode);
254
305
        }
255
306
 
 
307
        /**
 
308
         * @param string $source
 
309
         * @param string $destination
 
310
         * @param bool $overwrite
 
311
         * @return bool
 
312
         */
256
313
        public function move($source, $destination, $overwrite = false) {
257
 
                return @ssh2_sftp_rename($this->link, $source, $destination);
 
314
                return @ssh2_sftp_rename( $this->sftp_link, $source, $destination );
258
315
        }
259
316
 
 
317
        /**
 
318
         * @param string $file
 
319
         * @param bool $recursive
 
320
         * @param string|bool $type
 
321
         * @return bool
 
322
         */
260
323
        public function delete($file, $recursive = false, $type = false) {
261
324
                if ( 'f' == $type || $this->is_file($file) )
262
325
                        return ssh2_sftp_unlink($this->sftp_link, $file);
271
334
                return ssh2_sftp_rmdir($this->sftp_link, $file);
272
335
        }
273
336
 
 
337
        /**
 
338
         * @param string $file
 
339
         * @return bool
 
340
         */
274
341
        public function exists($file) {
275
342
                $file = ltrim($file, '/');
276
343
                return file_exists('ssh2.sftp://' . $this->sftp_link . '/' . $file);
277
344
        }
278
 
 
 
345
        /**
 
346
         * @param string $file
 
347
         * @return bool
 
348
         */
279
349
        public function is_file($file) {
280
350
                $file = ltrim($file, '/');
281
351
                return is_file('ssh2.sftp://' . $this->sftp_link . '/' . $file);
282
352
        }
283
 
 
 
353
        /**
 
354
         * @param string $path
 
355
         * @return bool
 
356
         */
284
357
        public function is_dir($path) {
285
358
                $path = ltrim($path, '/');
286
359
                return is_dir('ssh2.sftp://' . $this->sftp_link . '/' . $path);
287
360
        }
288
 
 
 
361
        /**
 
362
         * @param string $file
 
363
         * @return bool
 
364
         */
289
365
        public function is_readable($file) {
290
366
                $file = ltrim($file, '/');
291
367
                return is_readable('ssh2.sftp://' . $this->sftp_link . '/' . $file);
292
368
        }
293
 
 
 
369
        /**
 
370
         * @param string $file
 
371
         * @return bool
 
372
         */
294
373
        public function is_writable($file) {
295
374
                $file = ltrim($file, '/');
296
375
                return is_writable('ssh2.sftp://' . $this->sftp_link . '/' . $file);
297
376
        }
298
 
 
 
377
        /**
 
378
         * @param string $file
 
379
         * @return int
 
380
         */
299
381
        public function atime($file) {
300
382
                $file = ltrim($file, '/');
301
383
                return fileatime('ssh2.sftp://' . $this->sftp_link . '/' . $file);
302
384
        }
303
385
 
 
386
        /**
 
387
         * @param string $file
 
388
         * @return int
 
389
         */
304
390
        public function mtime($file) {
305
391
                $file = ltrim($file, '/');
306
392
                return filemtime('ssh2.sftp://' . $this->sftp_link . '/' . $file);
307
393
        }
308
394
 
 
395
        /**
 
396
         * @param string $file
 
397
         * @return int
 
398
         */
309
399
        public function size($file) {
310
400
                $file = ltrim($file, '/');
311
401
                return filesize('ssh2.sftp://' . $this->sftp_link . '/' . $file);
312
402
        }
313
403
 
 
404
        /**
 
405
         * @param string $file
 
406
         * @param int $time
 
407
         * @param int $atime
 
408
         */
314
409
        public function touch($file, $time = 0, $atime = 0) {
315
410
                //Not implemented.
316
411
        }
317
412
 
 
413
        /**
 
414
         * @param string $path
 
415
         * @param mixed $chmod
 
416
         * @param mixed $chown
 
417
         * @param mixed $chgrp
 
418
         * @return bool
 
419
         */
318
420
        public function mkdir($path, $chmod = false, $chown = false, $chgrp = false) {
319
421
                $path = untrailingslashit($path);
320
422
                if ( empty($path) )
331
433
                return true;
332
434
        }
333
435
 
 
436
        /**
 
437
         * @param string $path
 
438
         * @param bool $recursive
 
439
         * @return bool
 
440
         */
334
441
        public function rmdir($path, $recursive = false) {
335
442
                return $this->delete($path, $recursive);
336
443
        }
337
444
 
 
445
        /**
 
446
         * @param string $path
 
447
         * @param bool $include_hidden
 
448
         * @param bool $recursive
 
449
         * @return bool|array
 
450
         */
338
451
        public function dirlist($path, $include_hidden = true, $recursive = false) {
339
452
                if ( $this->is_file($path) ) {
340
453
                        $limit_file = basename($path);