I would like to list the directory files on another server
I am connected to another server using the ssh2_connect function, the connection is going well and I can get the file I need, but I'm not sure how the files can be listed.
Any help is determined!
You can use ssh2_sftp and opendir , for example:
<?php $connection = ssh2_connect('shell.example.com', 22); ssh2_auth_password($connection, 'username', 'password'); $sftp = ssh2_sftp($connection); $sftp_fd = intval($sftp); $handle = opendir("ssh2.sftp://$sftp_fd/path/to/directory"); echo "Directory handle: $handle\n"; echo "Entries:\n"; while (false != ($entry = readdir($handle))){ echo "$entry\n"; }
, - , PHP 5.6.28, , , , intval() SFTP-/
PHP 5.6.28
intval()
$handle = opendir("ssh2.sftp://".intval($sftp)."/path/to/directory");
http://www.php.net/manual/en/function.ssh2-exec.php
You give it a command ls, assuming it is a UNIX-based system (usually this is the case), otherwise an OP command, such as dirfor Windows.
ls
dir
<?php $connection = ssh2_connect('shell.example.com', 22); ssh2_auth_password($connection, 'username', 'password'); $stream = ssh2_exec($connection, 'ls'); ?>
Source: https://habr.com/ru/post/1663605/More articles:How to convert string date without zero padding and delimiter to DateTime - c #How to get rid of jenkins loading errors? - continuous-integrationОшибка "Не найдена" при загрузке файла с помощью jquery и handler (ashx) - c#What does a static method / variable really refer to in java if the object has not been initialized? - javaSegmentation error on fopen using sftp and ssh2 - segmentation-faultReact Redux - transfer data to components via props or connect - reactjsRotate text labels secondary axis - rRedux provider does not miss props / state - javascriptmissing region; use: region option or export region name for ENV ['AWS_REGION'] - ruby | fooobar.comТестер-испытатель замораживается при работе на бамбуке - node.jsAll Articles