Jonathan has asked for the wisdom of the Perl Monks concerning the following question:

I've noticed that when download links/buttons on web pages are often perl scripts. What are they doing? How can I create a web page whereby a link ftp's the file to the client automatically?

I would rather have my ignorance than another man's knowledge, because I have so much more of it.
Mark Twain

Replies are listed 'Best First'.
Re: FTP from web pages
by ChOas (Curate) on Dec 20, 2000 at 15:07 UTC
    Hi There!

    Well.... what they can do is this:
    #!/usr/bin/perl -wT; sub LogAllKindOfInformationOnThisUser; LogAllKindOfInformationOnThisUser; print "Location: ftp://filetheuserrequested\n\n"; #END
    This will redirect the browser to the ftp file
    and you may choose to save it, or the page you're
    being redirected to might refresh to the ftp URL
    through a META refresh tag...

    'They' can do anything...'they' are evil....

    Stand up to them

    GreetZ!,
      ChOas

    ps: sub LogAllKindOfInformationOnThisUser {#Be Creative};
      The other way (useful when generating files or extracting them from somewhere) is to:
      print "Content-Type: image/gif\n\n"; #for example while (<YOUR_FILE>) { print; }
      </CODE>
      -- Daniellek
        This is quite a nice way of doing it. However, if the script that prints this is called "download.pl" then your browser will prompt to save the gif as download.pl.

        You can supply a different default filename by adding this to the headers:
        print "Content-Disposition: attachment;filename=filename.ext";
        where you can change filename.ext to whatever you want.
Re: FTP from web pages
by steveAZ98 (Monk) on Dec 20, 2000 at 19:30 UTC
    We use it to keep track of how many downloads a file gets ( or at least attempted downloads ) and to what ip they're downloading from. Obviously this is not 100% reliable data, but it gives clients a feel for what is popular and what isn't. The way to the user's information is through the use of enviorment variables i.e. $ENV{'REMOTE_ADDR'} And to create it you do what chOas has said.
    HTH
      I don't know what server you're using, but this is info that is in the logs. The easy way out would be to parse those logs rather than interrupt the otherwise straightforward HTTP process.
        It depends on how apache is configured. You may have the general log just log IP, time, and file. You don't want it to have Referer, User-Agent, etc except for the files gotten from FTP. I don't care if you use Linux with Mozilla coming from perlmonks to display a .gif, but I do care if all the people downloading a file have certain things in common. If I find out 50% of people downloading a program are using NT, but my program has a small bug with NT, then I'd probably fix it. Also, what if I have a specific version for NT, for Linux, for 95/98? I don't have to trust the user to download the right one, my script does it for me.