我想在其他服务器中列出目录的文件
我使用ssh2_connect函数连接到另一台服务器连接正常,我能够获取所需的文件,但我不知道如何列出文件.
任何帮助都是适当的!
Eli*_*les 36
<?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";
}
Run Code Online (Sandbox Code Playgroud)
小智 22
如果有人正在努力让这个工作,并且你正在运行PHP 5.6.28那里有一个最近的更新,要么创建了一个要求,要么引入了一个intval()必须在每个SFTP文件夹/文件访问功能上使用的错误:
$handle = opendir("ssh2.sftp://".intval($sftp)."/path/to/directory");
Run Code Online (Sandbox Code Playgroud)