0

Am trying to extract a .tar file in the "/" directory of a remote server (server2), using the ssh2_exec() function from a php file located in another server (server1).

php file in server1:

<?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 : I was able to extract the file in "/home" directory using this:

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

Thank you.

gouyez
  • 93
  • 1
  • 2
  • 7

0 Answers0