To list directory contents:
<?php
$connection = ssh2_connect(\"hostname\", 22);
ssh2_auth_password($connection,\"username\", \"password\"); // or use any of the ssh2_auth_* methods
$sftp = ssh2_sftp($connection);
$dh = opendir(\"ssh2.sftp://$sftp/path/to/dir/\");
while (($file = readdir($dh)) !== false) {
echo \"$file is in hostname:/path/to/dir\\n\";
}
closedir($dh);
?>
(thanks to Sara for assisting)