title: Shell commands in PHP does not execute on remote server
body: <p>I have one problem. I write a script in PHP which connect to a remote server. The script copy a file and looks like this</p>
  
  <pre><code>&lt;?php
  $pubKey = "/path/to/public/key";
  $privKey = "/path/to/private/key";
  $srcFile = "/path/to/local/app.apk";
  $dstFile = "/path/to/remote/app.apk";
  
  $con = ssh2_connect("xxx.xxx.xx.xxx", "22", array("hostkey" =&gt; "ssh-rsa"));
  
  if(ssh2_auth_pubkey_file($con, "user", $pubKey, $privKey, "pw"))
  {
      sftp = ssh2_sftp($con);
      $sftpStream = fopen("ssh2.sftp://" . $sftp . $dstFile, "w");
      try
      {   
          if(!$sftpStream) throw new Exception("Could not open remote file: " . $dstFile);
          $dataToSend = file_get_contents($srcFile);
          if($dataToSend === false) throw new Exception("Could not open local file: " . $srcFile);
          if(fwrite( $sftpStream, $dataToSend) === false) throw new Exception("Could not send data from file: " . $srcFile);
          fclose($sftpStream);
          $shell = ssh2_shell($con, "xterm");
          fwrite($shell, "su system");
          fwrite($con, "pm install -r " . $dstFile);
          echo "passed through";
      } 
      catch (Exception $e)
      {
          error_log("Exception: " . $e-&gt;getMessage());
          fclose($sftpStream);
      }
  }
  ?&gt;
  </code></pre>
  
  <p>The method <code>ssh2_scp_send</code> always failed so I tried it like this way and it works fine. The method <code>ssh2_scp_send</code> return an error like</p>
  
  <pre><code>PHP Warning:  ssh2_scp_send(): Failed copying file in /srv/www/htdocs/index.php on line 10
  </code></pre>
  
  <p>and line 10 was the method. I have had the correct permission on the remote server and on my local pc.</p>
  
  <p>I also tried something like this</p>
  
  <pre><code>ssh2_exec($con, "su system");
  ssh2_exec($con, "pm install -r " . $dstFile);
  </code></pre>
  
  <p>I have tried to write the path to the app.apk manual too, but nothing works. It doesn't install the app on the remote server but it walks through my code because my website is displaying the message "passed through".</p>
  
  <p>What can be the reason why the <code>command</code> does not executed on the <code>shell</code> on my <code>remote server</code>?</p>