0

我正在尝试使用位于另一台服务器 (server1) 中的 php 文件中的 ssh2_exec() 函数在远程服务器 (server2) 的“/”目录中提取 .tar 文件。

server1 中的 php 文件:

<?php
$p_main_ip = 'xxx.xxx.xxx.xxx'; // ip of the server2
$user = 'root';
$p_password = 'password'; // server2 root password
   $connection = ssh2_connect($p_main_ip, 22);
   if($connection)
   {
      if(ssh2_auth_password($connection, $user, $p_password))
      {
        $stream = ssh2_exec($connection, 'tar xvpfz /home/t.tgz -C /');
      }
   }
?>

PS:我能够使用以下方法在“/home”目录中提取文件:

$stream = ssh2_exec($connection, 'tar xvpfz /home/t.tgz -C /home');

谢谢你。

4

0 回答 0