I have a problem with ssh_exec() refusing to execute the "cd" command.
If I log into the server directly and execute the command, it works fine, so I don't think the problem is with my team.
My code is as follows:
$str = ssh2_exec($sshStream, 'cp /var/www/compressed.tar.gz /var/www/vhosts/demo-domain1.com/httpdocs/'); $errstr = ssh2_fetch_stream($str, SSH2_STREAM_STDERR); stream_set_blocking($str, true); stream_set_blocking($errstr, true); echo "Output: " . stream_get_contents($str); echo "Error: " . stream_get_contents($errstr); $str = ssh2_exec($sshStream, 'cd /var/www/vhosts/demo-domain1.com/httpdocs/'); $errstr = ssh2_fetch_stream($str, SSH2_STREAM_STDERR); stream_set_blocking($str, true); stream_set_blocking($errstr, true); echo "Output: " . stream_get_contents($str); echo "Error: " . stream_get_contents($errstr); $str = ssh2_exec($sshStream, 'tar xzf c-class.tar.gz'); $errstr = ssh2_fetch_stream($str, SSH2_STREAM_STDERR); stream_set_blocking($str, true); stream_set_blocking($errstr, true); echo "Output: " . stream_get_contents($str); echo "Error: " . stream_get_contents($errstr);
I am registered as root.
The first command runs correctly and copies the file to the specified location. The second command is not executed, but does not display errors. The third command displays an error (obviously, since the previous cd command does not work).
I know that he did not change dirs, because when I execute "pwd" he returns, saying that he is in the root directory.
As mentioned earlier, if I run commands from the shell, they execute fine, so I'm sure my syntax is 99.9% correct.
This is a dedicated server provided by 1 & 1, working with CentOS and Plesk 9.
php centos plesk
David cooke
source share