We are attempting to move only the files from a remote server and putting the files directories into our database, so we need to be able to distinguish between a file and a directory. We have successfully been able to connect via SSH2 and we are able to read and display the files and directories within the remote path top directory. However, we have not been able to locate a php script that will allow us to find whether the returned name is a directory or a file. Below are a few examples we have tried. Any help is greatly appreciated and we thank you in advance.
$connection = ssh2_connect('www.myremote.com', 22);
ssh2_auth_password($connection, 'user', 'pw');
$sftp = ssh2_sftp($connection);
// THIS WORKS NICELY TO DISPLAY NAME FROM REMOTE SERVER
$handle = opendir("ssh2.sftp://$sftp/remotepath/");
echo "Directory handle: $handle<br>";
echo "Entries:<br>";
while (false != ($entry = readdir($handle))){
echo "$entry<br>";
}
// ONE OPTION THAT DOES NOT WORK
$handle = opendir("ssh2.sftp://$sftp/remotepath/");
echo "<br><br>2Directory handle: $handle<br>";
echo "4Entries:<br>";
while (false != ($entry = readdir($handle))){
if (is_dir(readdir($handel.''.$entry) ) ) {echo "<strong>$entry</strong><br>"; } else {
echo "$entry<br>"; //}
}
// ANOTHER OPTION THAT RETURNS AN EMPTY RESULT
$files = scandir('ssh2.sftp://'.$sftp.'/remotepath/');
foreach ($files as $file):
if (is_dir('ssh2.sftp://'.$sftp.'/remotepath/'.$file) ) {"<strong>".$file."</strong><br>"; } else { $file.'<br>'; }
endforeach;
'; if (ssh2_exec($connection, 'find /remotepath/'.$file.' -maxdepth 1 -type d -name "*"') ) {"".$file."
"; } else { $file.'-344
'; } endforeach; – ggSmith Aug 02 '13 at 23:34