There are two different things you have to keep in mind when working with 
paths from the cgi-bin on a Windows machine -- access for Perl, and access 
for the web.

When I want to give Perl access to something, I usually use Windows style 
paths -- this avoids the confusion that can arise with permissions using 
Unix style relative paths.  You have to be careful with this way of doing 
things, because you're bypassing all of the checks that the server does to 
make sure that the cgi-bin user is authorized to access a certain directory.

When you're producing HTML links on a web page that will give access to 
files, you obviously have to use URL paths.  Which is where your problem is 
arising, I believe.  Try:

print qq~<a href="ftp://path/to/ftp/files";>Link Text</a>~;

note the URL does not use relative paths, and has forward slashes.

Also, as a pure style note, you should be using a foreach loop, instead of 
a while loop, and you can avoid your check for "." and ".." if you get your 
file list using grep{}

<code>

my $sDirectory = "C:\My\Directory";
my $sURLRoot = "ftp://My/Directory";;
opendir(DIR, $sDirectory) || die("Couldn't open directory $sDirectory: $!");
my @asFiles = grep{ $_ =~ /\.zip$/ } readdir DIR; # change regular 
expression to suit your needs
closedir DIR;
print qq~<a href="$sURLRoot/$_">$_</a><br>\n~ foreach @asFiles;

</code>



At 18:40 05.07.2001 -0500, SAWMaster wrote:
>Hi group!
>
>Little bit of background.  I made a perl cgi that scans a directory for 
>files and auto generates a html page with hyperlinks to download whatever 
>files are in the directory.  I don't
>know if there's an easier way to do this than what I did (built it from 
>scratch) but I'm doing this to learn Perl, not to make things easy.  I had 
>this working locally through
>localhost, using the full path to the files, but it won't work if someone 
>tries to access it remotely.  Anyway, on to the problem.
>
>I'm having trouble writting my absolute path for a link to a .zip file in 
>a cgi script.
>
>Here's my code.
>
>while($i < ($#filelist))
>{
>         if ((@filelist[$i] ne '.') && (@filelist[$i] ne '..'))
>         {
>             print "<A HREF = 
> \"ftp\\public\\downloads\\assortedfiles\\@filelist[$i]\">@filelist[$i]</A>";
>             print "<BR>\n";
>         }
>         $i++;
>}

Aaron Craig
Programming
iSoftitler.com

Reply via email to