For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2004 > Streaming a file to a remote user









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Streaming a file to a remote user
Jason Price

2004-03-26, 11:14 pm

I'm trying to figure out a way to stream a file to a remote user, and be =
able to determine that the download completed, so I can delete the file =
being streamed. I may be missing an obvious way to do this, so I'm =
hoping you all can help me out.

Here's the sequence of events I'm after:

1. User clicks URL pointing to perl script.
2. Perl script pulls file out of LDAP, and writes it temporarily to =
disk.
3. File is uudecoded on the disk.
4. Decoded file is streamed to user, who saves the file locally.
5. Once it is determined that the download is complete, the temp file =
on the web server is deleted.


Steps 4 and 5 are what I'm really after - the rest is relatively =
straight forward. For security reasons, we don't want the file to =
remain on the web server filesystem any longer than it has to, which is =
why I need to delete it after being downloaded. Emailing the file is =
not an option, also due to security reasons.

Can anyone help me out with a way to do this?

Thanks.

Jason
Paul D. Kraus

2004-03-26, 11:14 pm

On Thursday 25 March 2004 12:02 pm, Price, Jason (TLR Corp) wrote:
> I'm trying to figure out a way to stream a file to a remote user, and be
> able to determine that the download completed, so I can delete the file
> being streamed. I may be missing an obvious way to do this, so I'm hoping
> you all can help me out.
>
> Here's the sequence of events I'm after:
>
> 1. User clicks URL pointing to perl script.
> 2. Perl script pulls file out of LDAP, and writes it temporarily to disk.
> 3. File is uudecoded on the disk.
> 4. Decoded file is streamed to user, who saves the file locally.
> 5. Once it is determined that the download is complete, the temp file on
> the web server is deleted.
>
>
> Steps 4 and 5 are what I'm really after - the rest is relatively straight
> forward. For security reasons, we don't want the file to remain on the web
> server filesystem any longer than it has to, which is why I need to delete
> it after being downloaded. Emailing the file is not an option, also due to
> security reasons.
>
> Can anyone help me out with a way to do this?


You should try posting this on the cgi list instead. You would me more likely
to get a response.

Philipp Traeder

2004-03-26, 11:15 pm

> I'm trying to figure out a way to stream a file to a remote=20
> user, and be able to determine that the download completed,=20
> so I can delete the file being streamed. I may be missing an=20
> obvious way to do this, so I'm hoping you all can help me out.
>=20
> Here's the sequence of events I'm after:
>=20
> 1. User clicks URL pointing to perl script.
> 2. Perl script pulls file out of LDAP, and writes it=20
> temporarily to disk.
> 3. File is uudecoded on the disk.
> 4. Decoded file is streamed to user, who saves the file locally.
> 5. Once it is determined that the download is complete, the=20
> temp file on the web server is deleted.
>=20
>=20
> Steps 4 and 5 are what I'm really after - the rest is=20
> relatively straight forward. For security reasons, we don't=20
> want the file to remain on the web server filesystem any=20
> longer than it has to, which is why I need to delete it after=20
> being downloaded. Emailing the file is not an option, also=20
> due to security reasons.
>=20
> Can anyone help me out with a way to do this?


Hi Jason,

maybe I don't get the point, but I don't think you need to do anything
special but=20
sending an HTTP header and the file's content - something like:

#!c:/perl/bin/perl.exe -w

use strict;
use FileHandle;

print "content-type: text/plain\n\n";

# this would be the point to pull the file out of LDAP and decode =
it...

# open the file you need to open, convert/decode it
my $fh =3D new FileHandle;

open ($fh, "dynamicdownload.pl") or print "could not open the file! :
$!\n";
while (<$fh> ) {
print "$. $_";
}
close ($fh) or print "could not close the file\n";

# commit suicide
unlink "dynamicdownload.pl";

Save this into a file called "dynamicdownload.pl" and put it into your =
web
server=B4s
cgi-bin directory.
The script will open itself, print itself out with line numbers in =
front,
and delete
itself afterwards (be careful! ;-) ). If I understand you correctly, =
you
would just
need to insert the connect to LDAP in front and change the name of the =
file
that should
be opened for reading and deleted...or do I get something wrong here?

HTH,

Philipp
Wiggins D Anconia

2004-03-26, 11:15 pm



>
> Hi Jason,
>
> maybe I don't get the point, but I don't think you need to do anything
> special but
> sending an HTTP header and the file's content - something like:
>
> #!c:/perl/bin/perl.exe -w
>
> use strict;
> use FileHandle;
>
> print "content-type: text/plain\n\n";
>
> # this would be the point to pull the file out of LDAP and decode it...
>
> # open the file you need to open, convert/decode it
> my $fh = new FileHandle;
>
> open ($fh, "dynamicdownload.pl") or print "could not open the file! :
> $!\n";
> while (<$fh> ) {
> print "$. $_";
> }
> close ($fh) or print "could not close the file\n";
>
> # commit suicide
> unlink "dynamicdownload.pl";
>
> Save this into a file called "dynamicdownload.pl" and put it into your web
> serverīs
> cgi-bin directory.
> The script will open itself, print itself out with line numbers in front,
> and delete
> itself afterwards (be careful! ;-) ). If I understand you correctly, you
> would just
> need to insert the connect to LDAP in front and change the name of the

file
> that should
> be opened for reading and deleted...or do I get something wrong here?
>


Sounds right to me, except I think you can go one step further, assuming
you can open the file from LDAP as a handle, stream the handle through
the decoder, then there is no reason to ever store the file to the local
disk, this can be done in memory (which is still not absolutely secure,
but generally more so than the local disk), then stream the file to the
browser. No need to worry about unlinking a temp file.

Of course, the question then becomes how are you accessing your LDAP
store and/or doing the decoding.

http://danconia.org

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com