Welcome to WebmasterWorld Guest from 54.198.69.193

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

     
5:18 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



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

6:47 pm on Jul 6, 2005 (gmt 0)

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



What error messages are you getting?
7:31 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



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...]

8:05 pm on Jul 6, 2005 (gmt 0)

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



How do you have the remote directory setup? As a Network File Share (NFS)? Are you accessing this from a *nix machine as well?
12:11 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



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.

12:57 pm on Jul 7, 2005 (gmt 0)

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



Then the directory path should look like that defined in the samba share, something like:
$dir = "/theotherserver/public";
1:30 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



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.

12:41 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Is it even possible to do what I want to do in PHP?
1:27 pm on Jul 8, 2005 (gmt 0)

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



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";
 

Featured Threads

Hot Threads This Week

Hot Threads This Month