Not able to copy the file in perl cgi script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to copy the file in perl cgi script
# 1  
Old 06-12-2013
Not able to copy the file in perl cgi script

Hello experts,

I am facing an very typical problem and hope the issue can be solved.

I have a page download.cgi in /cgi-bin folder.

Code:

use CGI;
use CGI::Carp qw ( fatalsToBrowser );  
use File::Copy

copy("C:\\Program Files\\Apache Software Foundation\\Apache2.2\\cgi-bin\\tcstemp\\$reportname","H:\\") or die("cannot copy file... giridhar $!");

print "<center><table border=0>";
print "<tr><td aligh=left>";
print qq~<a href="H:\\$report_name"><img src="/images/xlsx.png" width=40 height=40></a>~;
print qq~<a href="C:\\reports\\$report_name"><img src="/images/csv.jpg" width=40 height=40></a>~;
print "</td></tr>";
print "</table></center>";


But I am not able to copy the file to other drive( in windows).
I am able to run the cgi file in browser and it is showing an error message

Code:
Software error:
Cannot copy file at C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/tcstemp/temp_final_report.cgi line 315.


I have tried multiple ways to download the file but none of them worked.

Instead of copy the file to other drive I gave the file name directly in the link to download but no luck.

And also the below way calling perl script to cgi script to copy the file to another directory. But still no luck

Code:
use CGI;
use CGI::Carp qw ( fatalsToBrowser );  
use File::Copy

`perl filecopy.pl $reportname` or die("Cannot copy file");

print "<center><table border=0>";
print "<tr><td aligh=left>";
print qq~<a href="H:\\$report_name"><img src="/images/xlsx.png" width=40 height=40></a>~;
print qq~<a href="C:\\reports\\$report_name"><img src="/images/csv.jpg" width=40 height=40></a>~;
print "</td></tr>";
print "</table></center>";

filecopy code

Code:
use File::Copy;
use strict;
use warnings;


my $report_name = $ARGV[0];

copy("C:\\Program Files\\Apache Software Foundation\\Apache2.2\\cgi-bin\\tcstemp\\$report_name","H:\\") or die("cannot copy file... giridhar $!");


Could anyone please let me know what went wrong....

Tons of thanks....!!!
# 2  
Old 06-12-2013
Did you try 'use Win32' ?
Code:
Win32::CopyFile(FROM, TO, OVERWRITE)

This User Gave Thanks to rajamadhavan For This Post:
# 3  
Old 06-12-2013
But I am receiving an error message.

Win32::CopyFile("C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin\tcstest\$report_name", "H:\$report_name","H:\$report_name") or die("Cannot copy file");
# 4  
Old 06-12-2013
The third argument is not required or can be set to 0.

Please check the correct syntax here

Win32::kernel32 - search.cpan.org
This User Gave Thanks to rajamadhavan For This Post:
# 5  
Old 06-12-2013
Many thanks Raja...

the file got copied but copied with 0 bytes. I am not able to open the file
and had an error message while opening the copied file

Code:
Excel cannot open the file filename.xlsx because the file format or 
file extension is not valid. Verify that the file has not been corrupted 
and that the file extension matches the format of the file

Could you please let know what can be the possible mistake...

Thanks in advance...
# 6  
Old 06-12-2013
Also attaching the original script....
# 7  
Old 06-12-2013
Not sure. May be try giving only the destination path instead of the complete file name in the "to" argument.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl CGI : unable to download the excel sheet from perl cgi page

Hi All, I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet. I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet. print "<center><table... (2 Replies)
Discussion started by: scriptscript
2 Replies

2. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

3. Shell Programming and Scripting

Perl : embedding java script with cgi perl script

Hi All, I am aware that html tags can be embedded in cgi script as below.. In the same way is it possible to embed the below javascript in perl cgi script ?? print("<form action="action.htm" method="post" onSubmit="return submitForm(this.Submitbutton)">"); print("<input type = "text"... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

5. Web Development

problem with exporting vairable from one perl cgi to another perl cgi script while redirecting.

Can anyone tell me how to export a variable from one perl CGI script to another perl cgi script when using a redirect. Upon running the login.pl the user is prompted to enter user name and password. Upon entering the correct credentials (admin/admin) the user is redirected to welcome page. My... (3 Replies)
Discussion started by: Arun_Linux
3 Replies

6. Web Development

perl cgi script not working

Hello, Met a problem learning perl cgi script. 1 #!/usr/bin/perl -wT 2 3 use strict; 4 use CGI qw(:standard); 5 6 my $q = new CGI; 7 8 my $filename = $q->param('/home/yifangt/hello.cgi'); 9 my $contenttype = $q->uploadInfo($filename)->{'Content-Type'}; 10... (5 Replies)
Discussion started by: yifangt
5 Replies

7. Shell Programming and Scripting

perl - cgi script to read file from network

Hi, I have written a cgi perl script to read a file and display its contents. But if i have to access file located on network (local network), then i am unable to do so. However if i run script through shell it works, but through cgi script it generates no result. I have mapped network drive... (0 Replies)
Discussion started by: sarbjit
0 Replies

8. Shell Programming and Scripting

Perl or Awk script to copy a part of text file.

Hi Gurus, I'm a total newbie to Perl and Awk scripting. Let me explain the scenario, there is a DB2 table with 5 columns and one of the column is a CLOB datatype containing XML. We need all the 4 columns but only a portion of string from the XML column. We decided to export DB2 table to a .del... (26 Replies)
Discussion started by: asandy1234
26 Replies

9. Web Development

in cgi perl script a form

hi,i hav a form in cgi perl script.this script accepts a value from user from another html form, and depending upon this value,i need to disable /enable radio buttons in cgi-perl script wen second page is displayed on executing cgi perl script.how do i do it using javascript? (0 Replies)
Discussion started by: raksha.s
0 Replies

10. Shell Programming and Scripting

call shell script from perl cgi script problem

hi,, i have perl scipt with line : system('./try.sh $t $d $m'); in shell scipt try.sh i have the line: echo $1 its not printing value of $t that i hav passed..y is it so..i am running it from apache web server (2 Replies)
Discussion started by: raksha.s
2 Replies
Login or Register to Ask a Question