Do not use \n to end the command. Some server will fail to process. Use always the standard for PHP end of line: PHP_EOL
'suri at suribala dot com"'s example should be modified as follows (also change the double quotes to single, for better performance):
<?php
$con=ssh2_connect('192.168.0.1', 22);
ssh2_auth_password($con, 'user', 'password');
$shell=ssh2_shell($con, 'xterm');
fwrite( $shell, 'cd /dir_one;'.PHP_EOL);
fwrite( $shell, 'ls -la;'.PHP_EOL);
fwrite( $shell, 'cd /dir_two;'.PHP_EOL);
fwrite( $shell, 'ls -la;'.PHP_EOL);
?>
Cheers,
Pimmy