出于某种原因,当我尝试从远程服务器获取路径的状态时,它会一直返回false。我的代码应该在按钮点击时从远程服务器运行bash脚本并输出到网页。我的代码工作,我可以成功地将bash脚本输出回网页,但是,当我添加条件以检查文件是否存在时,它会转到else语句。我知道我的$sftp
很好,因为它不会抛出异常。
<?php
$gwUser = 'user';
$gwPwd = 'pwd';
$path = '/my/path/to/directory/bash.sh';
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
if ($connection = @ssh2_connect($gateway, 22)) {
ssh2_auth_password($connection, $gwUser, $gwPwd);
$sftp = @ssh2_sftp($connection);
if (!$sftp) throw new Exception("Could not initialize SFTP subsystem.");
$fileExists = file_exists('ssh2.sftp://' . $sftp . $path); //this returns "file doesn't exist"
if($fileExists) {
echo "the file exists";
} else {
echo "the file doesn't exist: " . $fileExists;
}
(code omitted for simplicity)
}
}
?>