I have below code to get content from remote directory.
$dirHandle = opendir("ssh2.sftp://$sftp/".PATH_OUT);
while (false !== ($file = readdir($dirHandle))) {
// something...
}
Now, the thing is, above code is in forloop
. when I put $dirHandle = opendir("ssh2.sftp://$sftp/".PNB_PATH_OUT);
outside of forloop then it gives me required result only for first record. So, obviously it's readdir
is not working for second record in forloop
.
How can I do this in such a way that I need to use opendir
only once and use that connection more than 1 time?
Required Solution
$dirHandle = opendir("ssh2.sftp://$sftp/".PATH_OUT);
for(...){
while (false !== ($file = readdir($dirHandle))) {
// something...
}
}