Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP ssh2_exec() from Ubuntu Server to Windows with OpenSSH in Cygwin - works but fails the second time
    primarykey
    data
    text
    <p>I had been using PHP's ssh_connect() and multiple ssh_exec() between two Ubuntu VMs without any problems. However, now I need to call <strong>multiple</strong> ssh_exec() from <strong>Ubuntu Server</strong> to <strong>Windows</strong> machine via <strong>OpenSSH/Cygwin</strong>. The result from ssh2_exec() in the following code prints an Array of files located at /var/www the first time, but returns empty array the second or more times. </p> <p>If I use ssh2_connect before the second ssh_exec() it returns an array of files again. I even attempted to use phpseclib but had the same problem. Also, I need to execute other commands like Git so PHP functions like opendir() or readdir() won't be sufficient to solve this problem.</p> <pre><code>&lt;?php $host = "10.xx.x.xx"; $username = "sagunms"; $password = "password"; $conn = ssh2_connect($host, 22); if (ssh2_auth_password($conn, $username, $password) === false) { throw new Exception('Login is invalid'); } //First time execution - returns array of files successfully $stream = ssh2_exec($conn, 'cd /var/www &amp;&amp; ls'); stream_set_blocking($stream, true); $cmdOutput = fread($stream, 4096); fclose($stream); $result = explode("\n", $cmdOutput); // Convert string to array print_r($result); // Print array echo "&lt;hr/&gt;"; //Second time execution - returns an "empty array" but no errors seen $stream = ssh2_exec($conn, 'cd /var/www &amp;&amp; ls'); stream_set_blocking($stream, true); $cmdOutput = fread($stream, 4096); fclose($stream); $result = explode("\n", $cmdOutput); // Convert string to array print_r($result); // Print array ?&gt; </code></pre> <p>Is there something in Cygwin OpenSSH that is causing this problem? Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload