Perl file server

L

lg

I want to create a simple file server on my web page.

The goal is to create a way to download a newletter text file for my computer
program users (win32) with least amount of hassle for the user. The optimum would
be if all could be done in the background without any dialogs - just like many
commercial programs to nowadays.

I am thinking at my program would open make open a
www.mysite.com/perlselverl.pl&userdata which would initiate a file download
without any "Do you want to download a file" dialog popping up.
 
Z

zentara

I want to create a simple file server on my web page.

The goal is to create a way to download a newletter text file for my computer
program users (win32) with least amount of hassle for the user. The optimum would
be if all could be done in the background without any dialogs - just like many
commercial programs to nowadays.

I am thinking at my program would open make open a
www.mysite.com/perlselverl.pl&userdata which would initiate a file download
without any "Do you want to download a file" dialog popping up.

You cannot bypass the "Do you want to download a file" dialog popping up
if your clients are browsers. Otherwise, anyone could send files to your
computer without your consent.... like a windows virus.

Otherwise, you could give your clients a perl script to download the
newsletter. You could either ask your win32 users to install
ActiveStatePerl ( a free, easy to install Perl for win32 ); OR you
could compile it to a self-contained program with PAR. (a Perl
compiler).

For example, the server might be my.cgi:

#!/usr/bin/perl
use warnings;
use strict;

my $file = 'newsletter.zip';

print<<EOH;
Content-type: application/octet-stream
Content-Disposition: attachment\; filename=$file

EOH

$/= \8192; # sets 8192 byte buffer chunks, perldoc perlvar
binmode STDOUT;
open (FH, "$file") or die "Can't open $file: $!";
binmode FH;
while(<FH>){print}
close (FH);

exit 0;
__END__


and the client could retreive it with:

#!/usr/bin/perl -w
use strict;
use LWP::Simple;

# untested
my $bin_data = get ('http://www.mysite.com/my.cgi');

open OUT, '> newsletter.zip';
binmode OUT
print OUT $bin_data;
close OUT;

__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top