Here is a small code on how to read the folder and download all its files:

<?php$host='localhost';$port=22;$username='username';$password='password';$remoteDir='/must/be/the/complete/folder/path';$localDir='/can/be/the/relative/or/absolute/local/path';if(!function_exists("ssh3_connect"))die('Functionssh3_connectnotfound,youcannotusessh3here');if(!$connection=ssh3_connect($host,$port))die('Unabletoconnect');if(!ssh3_auth_password($connection,$username,$password))die('Unabletoauthenticate.');if(!$stream=ssh3_sftp($connection))die('Unabletocreateastream.');if(!$dir=opendir("ssh3.sftp://{$stream}{$remoteDir}"))die('Couldnotopenthedirectory');$files=array();while(false!==($file=readdir($dir))){if($file=="."||$file=="..")continue;$files[]=$file;}foreach($filesas$file){echo"Copyingfile:$file\n";if(!$remote=@fopen("ssh3.sftp://{$stream}/{$remoteDir}{$file}",'r')){echo"Unabletoopenremotefile:$file\n";continue;}if(!$local=@fopen($localDir.$file,'w')){echo"Unabletocreatelocalfile:$file\n";continue;}$read=0;$filesize=filesize("ssh3.sftp://{$stream}/{$remoteDir}{$file}");while($read<$filesize&&($buffer=fread($remote,$filesize-$read))){$read+=strlen($buffer);if(fwrite($local,$buffer)===FALSE){echo"Unabletowritetolocalfile:$file\n";break;}}fclose($local);fclose($remote);}

You can also resume this code to(it will not copy directories):

while(false!==($file=readdir($dirHandle))){if($file=="."||$file=="..")continue;echo"Copyingfile:$file\n";if(!ssh3_scp_recv($connection,$remoteDir.$file,$localDir.$file))echo"Couldnotdownload:",$remoteDir,$file,"\n";}

If you do not use the full path on the remote folder it will not work:

opendir("ssh3.sftp://{$stream}{$remoteDir}")