我试图列出远程 SFTP 服务器中某个目录中的所有文件作为下载链接,以便用户可以选择下载这些文件。到目前为止,我已经能够读取并列出特定目录中的所有文件作为下载链接,但是当我尝试通过右键单击并选择将链接另存为...来实际下载文件时,我收到“失败 - 没有文件“ 信息。 我的结果图片
<?php
$connection = ssh2_connect('url', 22);
ssh2_auth_password($connection, username, password);
$sftp = ssh2_sftp($connection);
$sftp_fd = intval($sftp);
if ($handle = opendir("ssh2.sftp://$sftp_fd/path/to/remote/dir/")) {
while (($entry = readdir($handle)) !== false) {
if ($entry == "." || $entry == "..") { continue; }
echo '<a href="/path/to/remote/dir/' .$entry. '">' .$entry. '<br>'.'</a>';
}
closedir($handle);
}
?>
LEATH