if you use the Linux command line find this will help:
this is how you find only files named blah:
find . -type f -name *blah*
this is how you find only directories named blah:
find . -type d -name *blah*
in this case you could to the following to find all files in the /tmp directory (without going into the subdirectories of /tmp (maxdepth 1)) named anything:
$connection->exec('find /tmp -maxdepth 1 -type f -name "*"');
EDIT:
Ok, so here's a bit more code. This will connect to a server and echo a list of all directories in your home directory and then all files in your home directory:
$connection = ssh2_connect($host, 22);
ssh2_auth_password($connection, $user, $pass);
$the_stream = ssh2_exec($connection, '/usr/bin/find ~ -maxdepth 1 -type d');
stream_set_blocking($the_stream, true);
$the_result = stream_get_contents($the_stream);
echo "Directories only: <br><pre>" . $the_result . "</pre>";
fclose($the_stream);
$the_stream = ssh2_exec($connection, '/usr/bin/find ~ -maxdepth 1 -type f');
stream_set_blocking($the_stream, true);
$the_result = stream_get_contents($the_stream);
echo "Files only: <br><pre>" . $the_result . "</pre>";
fclose($the_stream);
You should be able to parse $the_result into an array by splitting on newlines or some such and get just the files or just the directories. Remove the "-maxdepth 1" from the find and you'll recurse through all subdirectories.