我正在尝试结合 ssh2_connect 实现 php,以便使用以下脚本在远程文件夹上解压缩:
$connection = ssh2_connect($ipaddress, 22);
if (!$connection) {
throw new Exception("Could not connect to server.");
}
if (!ssh2_auth_password($connection, $username, $password)) {
throw new Exception("Authentication failed!");
}
else {
$unzip = "unzip $filename";
//$unzip = "unzip $filename -d /home/upload/homes/folder/";
if ( ($stream = ssh2_exec( $connection, $unzip ) ) ){
$sftp = ssh2_sftp($connection);
ssh2_sftp_unlink($sftp, $filename);
}
}
我的 zip 文件包含多个文件,但 unzip 函数只返回 1 个 0kB 的文件。当我使用 ssh 登录时,我可以成功解压缩文件。有任何想法吗?