Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Counter for file download on perl

Alex Chupahin
Super Advisor

Counter for file download on perl

Hi!
http server WASD, all file are really present
and have RWED RWED RWED RWED.

This is simple perl code

-------------------------------------------
use VMS::Stdio qw( &flush &getname &remove &rewind &setdef &sync &tmpnam
&vmsopen &vmssysopen &waitfh &writeof );

my $file="vnc.zip";
my $fullpath="$file";
open E,">err.log";
$f = vmssysopen ("$file",O_RDONLY,0,"ctx=bin") or die $!;
close E;
print "Cache-control: no-cache\n";
print "Content-type: application/force-download\n";
print "Content-Length: ".(-s $fullpath)."\n";
print "Content-Disposition: attachment; filename=$file \n\n";
while (<$f>){print};close $f;
-------------------------------------------


WASD returns error 502

BUT!!
if I change $file="vnc.zip" to
$file="count.txt"

script allows me to save file. It is working!
What I'm doing wrong?

Please note - vnc.zip and count.txt are here and have full control
And one thing - $! is empty.
11 REPLIES
Alex Chupahin
Super Advisor

Re: Counter for file download on perl

In apache and HP perl 5.6.0 it works fine.

What should it be: bug in perl, WASD or in my head ?
Hein van den Heuvel
Honored Contributor

Re: Counter for file download on perl


What is the perl version you are trying now? 5.10?

What are the file attributes for the wroking file and for the failing (zip) file? stream_lf? fixed/512?

Can you not run and evaluate the script outside a web server context, simply on a command line?

If that fails, try to get an IO trace going
1) SET WATCH FILE/CLA=MAJOR
or
2) Place the file on an LD device and enable trace.

hth,
Hein.
Alex Chupahin
Super Advisor

Re: Counter for file download on perl

horrow is continueing:
Ok, using DCL:

$write sys$output "Cache-control: no-cache"
$write sys$output "Content-type: application/force-download"
$write sys$output "Content-Length: 1024"
$write sys$output "Content-Disposition: attachment; filename=","vnc.zip"
$write sys$output ""
$!
$ type vnc.zip


File is downloded. But corrupted.

Ok, I've wrote a simple C utility that opens binary file and put it into out.
Not help.

Is it possible task to make download counter in WASD??
Alex Chupahin
Super Advisor

Re: Counter for file download on perl

What is the perl version you are trying now? 5.10?

>What are the file attributes for the wroking file and for the failing (zip) file? stream_lf? fixed/512?


fixed 512.

>Can you not run and evaluate the script outside a web server context, simply on a command line?


In command line, how I say, it works fine
Also it works fine on my Apache environment

PERL 5.8.0
WASD (do not know version)
Alex Chupahin
Super Advisor

Re: Counter for file download on perl

In common case, I've decided my problem with DCL something like

$FILE="DISK$USER_1:[ALEXEY.PUBLIC_HTML.CGI-BIN]VNC.ZIP"
$SHORT="VNC.ZIP"
$SIZE=F$FILE_ATTRIBUTES("''FILE'","EOF") * 512
$write sys$output "Cache-control: no-cache"
$write sys$output "Content-type: application/force-download"
$write sys$output "Content-Length: ",SIZE
$write sys$output "Content-Disposition: attachment; filename=",SHORT
$write sys$output ""
$!

$type 'FILE'


But I do not understand behavor of perl with WASD.
So any suggestion would be nice...
Craig A Berry
Honored Contributor

Re: Counter for file download on perl

I don't know anything about WASD or how it embeds Perl, but I would think you'd want to use sysread rather than the implicit readline (<>) if this is binary data with fixed-length records, as it appears to be. See:

$ perldoc -f sysread

Regarding changing the name from vnc.zip to count.txt, there is nothing in Perl I'm aware of that would treat a file differently based on file type, so that would have to be something in WASD and/or your browser.

As far as $! being empty, you only check it after the initial open, so anything involved in reading the file or writing data down the pipe could fail silently.

BTW, Perl 5.8.0 is pretty ancient. 5.8.8 is current with release candidates for 5.8.9 now circulating if you have a compelling reason to stay with 5.8.x. I'd recommend 5.10.0 or later for any serious new work.
Alex Chupahin
Super Advisor

Re: Counter for file download on perl

Thank you Craig, it will be useful when script can read the file. But script died during open()
John Travell
Valued Contributor

Re: Counter for file download on perl

Alex,
What version WASD are you running ?
$ mcr ht_exe:httpd_ssl /version
or
$ mcr ht_exe:httpd /version
if you did not include SSL support when you installed it.
Versions prior to v8.2.0 were a little more particular about getting a "Status:",
"Content-type:" or "Location:" CGI header before any others. If your WASD version is of that vintage shuffling the order of the response headers may help.

Also is your perl up-to-date...
$ perl -v

Your script appears to work correctly on WASD/9.3.0 and perl v5.8.6.
'No 502, just a save dialog'
(tested by someone else, I have WASD but not perl on my VMS box)

You may also get significant value from the integrated 'WATCH' facility
http://wasd.vsm.com.au/ht_root/doc/htd/htd_2000.html


Finally, there is an active user community using and supporting WASD. I suggest you look on the product homepage for an email address for Mark Daniels, and contact him directly.
JT:
Wim Van den Wyngaert
Honored Contributor

Re: Counter for file download on perl

Don't know perl but content-length is the length in bytes of the whole file (not record length). Is it 1024 ? That could explain your corrupt file.

Wim
Wim
Wim Van den Wyngaert
Honored Contributor

Re: Counter for file download on perl

Sorry, see that the next sample you provided did it better.

I used the WATCH feature of WASD and found that "type" is not copying ALL the trailing binary zeroes in the file. But when using copy to sys$output I get them but zip is still not showing the content.

Wim
Wim
Wim Van den Wyngaert
Honored Contributor

Re: Counter for file download on perl

Miscounted. Ignore my previous post.

Wim
Wim