|
108 | 108 | * @method string|false realpath(string $path)
|
109 | 109 | * @method bool chdir(string $dir)
|
110 | 110 | * @method string[]|false nlist(string $dir = '.', bool $recursive = false)
|
111 |
| - * @method mixed[]|false rawlist(string $dir = '.', bool $recursive = false) |
112 | 111 | * @method void setListOrder(mixed ...$args)
|
113 |
| - * @method mixed[]|false stat(string $filename) |
114 |
| - * @method mixed[]|false lstat(string $filename) |
115 | 112 | * @method bool truncate(string $filename, int $new_size)
|
116 | 113 | * @method bool touch(string $filename, int $time = null, int $atime = null)
|
117 | 114 | * @method bool chown(string $filename, int|string $uid, bool $recursive = false)
|
@@ -234,24 +231,6 @@ public function login($username, ...$args)
|
234 | 231 | }
|
235 | 232 | }
|
236 | 233 |
|
237 |
| - /** |
238 |
| - * Parse Attributes |
239 |
| - * |
240 |
| - * See '7. File Attributes' of draft-ietf-secsh-filexfer-13 for more info. |
241 |
| - * |
242 |
| - * @param string $response |
243 |
| - * @return array |
244 |
| - * @access private |
245 |
| - */ |
246 |
| - protected function parseAttributes(&$response) |
247 |
| - { |
248 |
| - $r = $this->sftp->parseAttributes($response); |
249 |
| - if (isset($r['mode'])) { |
250 |
| - $r['permissions'] = $r['mode']; |
251 |
| - } |
252 |
| - return $r; |
253 |
| - } |
254 |
| - |
255 | 234 | /**
|
256 | 235 | * Defines how nlist() and rawlist() will be sorted - if at all.
|
257 | 236 | *
|
@@ -314,6 +293,72 @@ public function getSFTPObject()
|
314 | 293 | return $this->sftp;
|
315 | 294 | }
|
316 | 295 |
|
| 296 | + /** |
| 297 | + * Returns general information about a file. |
| 298 | + * |
| 299 | + * Returns an array on success and false otherwise. |
| 300 | + * |
| 301 | + * @param string $filename |
| 302 | + * @return array|false |
| 303 | + */ |
| 304 | + public function stat($filename) |
| 305 | + { |
| 306 | + $result = $this->sftp->stat($filename); |
| 307 | + if (isset($result['mode'])) { |
| 308 | + $result['permissions'] = $result['mode']; |
| 309 | + } |
| 310 | + return $result; |
| 311 | + } |
| 312 | + |
| 313 | + /** |
| 314 | + * Returns general information about a file or symbolic link. |
| 315 | + * |
| 316 | + * Returns an array on success and false otherwise. |
| 317 | + * |
| 318 | + * @param string $filename |
| 319 | + * @return array|false |
| 320 | + */ |
| 321 | + public function lstat($filename) |
| 322 | + { |
| 323 | + $result = $this->sftp->lstat($filename); |
| 324 | + if (isset($result['mode'])) { |
| 325 | + $result['permissions'] = $result['mode']; |
| 326 | + } |
| 327 | + return $result; |
| 328 | + } |
| 329 | + |
| 330 | + /** |
| 331 | + * Returns a detailed list of files in the given directory |
| 332 | + * |
| 333 | + * @param string $dir |
| 334 | + * @param bool $recursive |
| 335 | + * @return array|false |
| 336 | + */ |
| 337 | + public function rawlist($dir = '.', $recursive = false) |
| 338 | + { |
| 339 | + $result = $this->sftp->rawlist($dir, $recursive); |
| 340 | + if (!$result) { |
| 341 | + return false; |
| 342 | + } |
| 343 | + |
| 344 | + return self::rawlistHelper($result); |
| 345 | + } |
| 346 | + |
| 347 | + /** |
| 348 | + * Adds permissions variable to each array element |
| 349 | + */ |
| 350 | + private static function rawlistHelper(array $files) |
| 351 | + { |
| 352 | + foreach ($files as $file=>&$data) { |
| 353 | + if (is_array($data)) { |
| 354 | + $data = self::rawlistHelper($data); |
| 355 | + } else { |
| 356 | + $data->permissions = $data->mode; |
| 357 | + } |
| 358 | + } |
| 359 | + return $files; |
| 360 | + } |
| 361 | + |
317 | 362 | /**
|
318 | 363 | * __call() magic method
|
319 | 364 | *
|
|
0 commit comments