如何使用ssh2列出其他服务器中目录的文件 [英] How to list files of a directory in an other server using ssh2
本文介绍了如何使用ssh2列出其他服务器中目录的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想列出其他服务器中目录的文件
I would like to list the files of a directory in an other server
我已使用ssh2_connect函数连接到另一台服务器,连接进展顺利,我能够获取所需的文件,但不确定如何列出文件.
I am connected to an other server using ssh2_connect function the connection is going well and I am able to fetch a desired file but I am not sure how the files can be listed.
推荐答案
您可以使用 ssh2_sftp 和 opendir ,如下所示:
You can use ssh2_sftp and opendir, like this:
<?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";
}
这篇关于如何使用ssh2列出其他服务器中目录的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文