我正在使用 php 在 linux 中执行 find 命令以搜索目录中的文件并将其复制到另一个目录中。我的php代码是:-
<?php
include 'config.php';
$mxf = $_POST['year'];
$year = substr($mxf, 0, 4);
$ndrive = $_POST['ndrive'];
$command = 'find /var/www/html/collections/'.$year.'/ -name ' . $mxf . ' -exec cp {} ' . $ndrive . ' \;';
$stream = ssh2_exec($con, $command);
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo stream_get_contents($stream_out);
ssh2_exec($con, 'logout');
?>
现在,如果在目录中找不到请求的文件或服务器上不可用的文件,我希望该脚本返回 false。那么如何使用 ssh2_exec 命令处理此类错误。