V
V
Valery Ivanov2015-06-02 13:29:17
PHP
Valery Ivanov, 2015-06-02 13:29:17

How to scan a directory in php via sftp?

I need to fully scan a folder and all its subfolders for *.cfg files and output the path and file name together in an array, for example:
cfg/motd.cfg
server/perm.cfg
Google doesn't help or I can't find it.
It is necessary through SFTP, because RSA keys are used for authorization on the server.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tplus, 2015-06-02
@tplus

Documentation
php.net/manual/ru/function.ssh2-sftp.php Connection
class example
https://phptime.ru/php-features/ispolzovanie-ssh-i...
Getting a list of files
stackoverflow.com/questions/8840883 /how-to-list-fi...

A
Alexey Gnevyshev, 2021-02-27
@iResource

You can install this library via Composer:
https://github.com/hugsbrugs/php-sftp
- and work through it, for example:

require_once dirname(__DIR__).'/vendor/autoload.php';
use Hug\Sftp\Sftp as Sftp;
print_r(Sftp::scandir($server, $user, $password, '/home/a/agnevy6d', $port = 22, $timeout = 10));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question