I trying to set up a script that copies a tar archive to a remote server and then extracts it. The problem is that after the tar archive is extracted only half of what should be in the extracted folder is actually there.

Here is the Copy function

```
private function sendFile () {
  $connection1 = ssh2_connect($this->hostserver, 22);
  echo 'opened connection to remote server'."\n";
  if (ssh2_auth_password($connection1, $this->username, $this->password)) {
    echo "authentication Successful!\n";
  } else {
    die('authentication Failed...');
  }

  $localFolder  = $this->home.'/deployable/'.$this->extractedFolderName.'.tar';
  $remoteFolder = '/home/'.$this->username.'/'.$this->extractedFolderName.'.tar';

  if(ssh2_scp_send($connection1,$localFolder , $remoteFolder, 0777)) {
    echo 'file uploaded'."\n";
    ssh2_exec($connection1, 'exit');   
    echo 'closed connection1'."\n";

    $this->copySitesFolderIntoNew();

  } else {
    echo 'upload failed'."\n";
    ssh2_exec($connection1, 'exit');   
    echo 'closed connection1'."\n";
  };

```

...followed by the copySiteFolderIntoNew function which has the purpose to copy the current 'site' folder of my drupal installation into the newly extracted archive. (All it does currently is extracting the archive)

```
private function copySitesFolderIntoNew () {
  $connection2 = ssh2_connect($this->hostserver, 22);
   echo 'opened  connection2'."\n";
  if (ssh2_auth_password($connection2, $this->username, $this->password)) {
    echo "Authentication Successful!\n";
  } else {
    die('Authentication Failed...');
  }

  if(ssh2_exec($connection2, 'sudo tar -xvf /home/robot/drupal-7.38.tar 2>tar.log')){
    echo 'extracted file'."\n";
  } else {
    die('extract failed');
  }

 // ssh2_exec($connection, 'sudo chmod ugo+rwx drupal-7.38.tar');
 // ssh2_exec($connection, 'sudo cp /srv/www/vhosts/test_content/sites -R /home/llrobot/drupal-7.38');
    ssh2_exec($connection2, 'exit');   
    echo 'closed connection2'."\n";
}   

```

Here is the funny bit: if the line 

```
sudo tar -xvf /home/robot/drupal-7.38.tar 2>tar.log

```

is being executed by the script half of the archive does not end up on the server folder.

If I go to the server (ssh) and execute the line (extracting the same archive) the whole archive gets extracted.

Anyone any ideas?