Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using the directoryIterator class to read remote directory

Posted on 2008-10-13
4
Medium Priority
?
809 Views
Last Modified: 2009-07-29
Hi,
I am using the class to get a list of file names on my localhost like this:

foreach ( new DirectoryIterator('c:/wamp/www/name/images/etc') as $file)
{
      if (!$file->isDot())
      {
            print $file->getFilename();
      }
}

All fine.

What I want to do is to read the same directory on a remote server - to make sure when I copied the files using FTP they were all done. However, when I try placing the path in the constructor like this:

foreach ( new DirectoryIterator('/home/sites/domainname.com/public_html/images/etc') as $file)
{
      if (!$file->isDot())
      {
            print $file->getFilename();
      }
}

I get errors. Is it not possible to do this?

Any help much appreciated!

Daisy
0
Comment
Question by:daisydoos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:AlexanderR
ID: 22704721
Perhaps its a security restriction on the server.  Do you HAVE to use full path?  Can your class just accept "images/etc"?
0
 

Author Comment

by:daisydoos
ID: 22705142
Hi Alexander,

Thanks for your response.

The thing is I want to compare the contents of the directory on localhost eg images/products and do the same on the remote server. If use images/products for the remote query, I am just pulling off the files on my local machine.

Any other thoughts on how I can do this?

Many thanks

Daisy
0
 
LVL 11

Accepted Solution

by:
AlexanderR earned 500 total points
ID: 22705218
Oh, sorry.
I thought both the images and the script gets uploaded.  So the script remains on your local computer but has to scan remote ftp site.  Am i correct this time?

What kind of errors do you get.  Do you use ftp specific functions , like ftp_nlist http://bs.php.net/manual/en/function.ftp-nlist.php.  You probably should post your DirectoryIterator for us to see.
0
 

Author Comment

by:daisydoos
ID: 22708906
Hi Alexander,

That's great - thanks! I am using this ftp_nlist in conjunction with the directoryIterator to compare the 2 directories - all is well - many thanks,

Daisy
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question