在php&中通过ssh2_exec执行find命令得到结果

时间:2015-06-22 08:00:42

标签: php ssh2-exec

我正在使用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命令处理这种类型的错误。

0 个答案:

没有答案