homepage Welcome to WebmasterWorld Guest from 54.166.113.249
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How do I get a list of files in a remote directory?
newbieatseo

10+ Year Member



 
Msg#: 9040 posted 5:18 pm on Jul 6, 2005 (gmt 0)

I have been trying to use this script to get a list of files on another linux box:

$dir = "\\theotherserver\public";

$dh = opendir($dir);

$i = 0;
while (false!== ($filename = readdir($dh)))
{
print $filename;

if($filename<>"." and $filename<>"..")
{
$array[$i] = $filename;
$i++;
}
}

Any tips or hints on how to get this to work?

Thanks,

Shawn

 

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 9040 posted 6:47 pm on Jul 6, 2005 (gmt 0)

What error messages are you getting?

newbieatseo

10+ Year Member



 
Msg#: 9040 posted 7:31 pm on Jul 6, 2005 (gmt 0)

Here are the errors I get when trying to run this:

PHP Warning: opendir(\\\\theotherserver\\public): failed to open dir: No such file or directory in /var/www/html/nballoys.htm on line 26, referer: [myserver...]

PHP Warning: readdir(): supplied argument is not a valid Directory resource in /var/www/html/nballoys.htm on line 29, referer: [myserver...]

File does not exist: /var/www/html/temp, referer: [myserver...]

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 9040 posted 8:05 pm on Jul 6, 2005 (gmt 0)

How do you have the remote directory setup? As a Network File Share (NFS)? Are you accessing this from a *nix machine as well?

newbieatseo

10+ Year Member



 
Msg#: 9040 posted 12:11 pm on Jul 7, 2005 (gmt 0)

Both machines are running Fedora Core 2.

The remote machine's file shares are created using Samba. The directory I am trying to access is a public directory that everyone has access to and it does exists despite what the error message says.

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 9040 posted 12:57 pm on Jul 7, 2005 (gmt 0)

Then the directory path should look like that defined in the samba share, something like:
$dir = "/theotherserver/public";

newbieatseo

10+ Year Member



 
Msg#: 9040 posted 1:30 pm on Jul 7, 2005 (gmt 0)

I have tried many different paths but none work.

The path on the remote computer in samba is: /home/public

If I use that path the code looks on the local computer which does not have that path.

Some of the paths I have tried:

\\theotherserver\public
//theotherserver/public
/theotherserver/home/public
/theotherserver/public
file://theotherserver/public

It doesn't seem to recognize a UNC path at all.

I have control of both machines and can make changes as needed for the most part.

newbieatseo

10+ Year Member



 
Msg#: 9040 posted 12:41 pm on Jul 8, 2005 (gmt 0)

Is it even possible to do what I want to do in PHP?

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 9040 posted 1:27 pm on Jul 8, 2005 (gmt 0)

Absolutely, and it works well. I use samba shares all the time. My suggestion would be to get your connection working first and then apply it to your $dir variable with PHP. What I mean is, try some command line work first. Are you able to run a simple listing command from the bash prompt?
ls -la /home/public

If not, you don't have your network share working. Once you get that working you simply use the same path in your $dir variable.
$dir = "/home/public";

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved