Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open directory failing

Status
Not open for further replies.

peterto

Programmer
Joined
Apr 23, 2007
Messages
4
Hi guys ,

I have doubt regarding opening directory on remote machine.....

From my local system i want to open remote system directory and i want to read the contents from that directory i used this bit of code for that,it is giving fail to read ........ but this code is working in local system can any one tell me the reason..please......

/*code for opening dir in local system*/**WORKING****/

$mydir = "C:\\Perl1\\bin\\testscripts\\kiranlearningexample";
if(opendir(DIR, $mydir)==0) {
print "fail to read\n";
}
@allfiles = readdir(DIR);
closedir(DIR);
print @allfiles;




/*code for opening dir in remote system*/**NOTWORKING****/

$mydir = "http:\\vss-srv\\Perl\\testscripts"; i tried this one also ($mydir = " if(opendir(DIR, $mydir)==0) {
print "fail to read\n";
}
@allfiles = readdir(DIR);
closedir(DIR);
print @allfiles;

Thanks.
 
This'll give you more information:
Code:
print "fail to read: $!\n";
The special $! variable will give you the reason the opendir failed.
 
Um...
can you use opendir on a http call?
Code:
$mydir = "http:\\vss-srv\\Perl\\testscripts";    i tried  this one also    ($mydir = "[URL unfurl="true"]http://vss-srv//Perl//testscripts")[/URL]

I would think that opendir would only work on local system dir's.

If this is a local system you are working on replace http:\\ with your local path/to/htdocs
 
Just like open(), opendir does not work with HTTP addresses.

You should have a non-HTTP path to get to the other machine. On Windows servers, for example, you'd go to \\servername\share-name

Code:
opendir (DIR, "\\\\office-computer\\some\\shared\\directory");

That would work just fine, assuming the computer's name on the network is "office-computer" and it's sharing something at that path.

If this isn't a Windows network, there should still be a format similar to this for Linux, or whichever OS this is for.

If you're trying to open a directory that is *not* within a local network, but somewhere else on the Internet, you can't use opendir over HTTP to open the directory. The best you would be able to do with HTTP is, if their web server allows directory listing, use LWP to get the directory index, and parse it to find all the files inside it, then use LWP to open individual files if you want to.

If the server has FTP, you can use one of the FTP modules from CPAN to connect to that server, in which directory listings and file reading are a lot easier than by using LWP and parsing web pages.

-------------
Cuvou.com | The NEW Kirsle.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top