freelanceprogrammers.org Forum Index » Perl

HELP in downloading files with this script


View user's profile Post To page top
foncesa05 Posted: Mon Mar 06, 2006 1:47 am


Joined: 06 Mar 2006

Posts: 1
HELP in downloading files with this script
Hello everybody,
I am very much depressed and unable to find a solution.
Please some one with the experties help me.
1] Below is my script which allows me to display the data from the
folders but it does not allow me to download the same `save target
as`
I don`t know what`s wrong i have made.

2] If there are files in the folder with the codes [i.e. 001
e.g.001salesoff.dat ] then this files are displayed as mentioned
above but suppose the files without the codes in the starting of the
file are not dislayed i need to add this that those files must also
be displayed to all. [e.g. incurred.txt] & they are are text files
with .txt extention.

Will some expert please help me, favour me in this hour of
difficulty and i shall be always be highly thankfull and obliged.

Thanking in advance.

[passfile.txt.pl]

test test 001
abcd joed 002

[main.pl]

#!/usr/bin/perl

push(@INC, `.`);
use CGI qw(:standard);
use LWP::Simple;

$cgi = CGI->new;

# /* Change This Line To Your CGI Bin and Perl file */
$this = "http://www.mysite.net/cgi-bin/main.pl";

# /* Change This Line To Your www folder, without the CGI-Bin */
$fpath = "http://www.mysite.net/";

# /* Change This To Your Literal Path */
$hpath = "/home/venus/public_html";

#$filepaths = "/var/www/bank/reports";
$filepaths = "/home/venus/reports";

# /* Change This To The Name Of The Password File */
$passfile = "passfile.txt.pl";

$fnames[0] = "inc";
$fnames[1] = "sal";
$fnames[2] = "inw";


if (param()) {
if (param(`cmd`) eq "auth") {
&authenticate;
&load_type_list;
} elsif (param(`fname`)) {
$incookie = $cgi->cookie(`buscode`);
if ($incookie eq "") {
&load_login;
} else {
&do_load_links;
}
} elsif (param(`getfile`)) {
$incookie = $cgi->cookie(`buscode`);
if ($incookie eq "") {
&load_login;
} else {
&get_file;
}
}
} else {
&load_login;
}


sub get_file
{
chomp($thefile = param(`getfile`));
chomp($cpath = param(`path`));
`cp $cpath/$thefile $hpath`;

print header;
print <<PAGE;
<HTML>
<HEAD>
<SCRIPT LANGUAGE="Javascript">
window.location = "$fpath/$thefile";
</SCRIPT>
</HEAD>
</HTML>
PAGE
}

sub load_login
{

# /* You Can Modify Everything Below print <<PAGE;, but stop
BEFORE PAGE */
print header;
print <<PAGE;
<HTML>
<HEAD>
<TITLE>File Download Program Thing</TITLE>
<SCRIPT LANGUAGE="Javascript">
/* Javascript Code Here */
function chk_fields()
{
uname =
document.loginfrm.uname.value;
pass =
document.loginfrm.pass.value;

if (uname == "") {
alert("I Need A
Username");
return false;
}

if (pass = "") {
alert("I Need A
Password");
return false;
}

document.loginfrm.submit();
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#000000" TEXT="#FFFFFF">
<FORM NAME="loginfrm" METHOD="POST" ACTION="$this">
<CENTER>
<H1>Please Login</H1>
<HR><BR>
<B>Username</B><BR>
<INPUT TYPE="TEXT"
NAME="uname"><BR><BR>
<B>Password</B><BR>
<INPUT TYPE="PASSWORD"
NAME="pass"><BR><BR>
<INPUT TYPE="HIDDEN" NAME="cmd"
VALUE="auth">
<INPUT TYPE="BUTTON" VALUE="Login"
onClick="chk_fields();">
<INPUT TYPE="BUTTON" VALUE="Cancel"
onClick="history.go(-1);"><BR>
</CENTER>
</FORM>
</BODY>
</HTML>
PAGE

&foot;
}

sub do_load_links
{
chomp($username = param(`uname`));
chomp($password = param(`pass`));
chomp($buscode = param(`bcode`));
chomp($fbname = param(`fname`));
$cpath = "$filepaths/$fbname";
@files = &get_file_list($cpath);

# /* You Can Modify Everything Below print <<PAGE;, but stop
BEFORE PAGE */
print header;
print <<PAGE;
<HTML>
<HEAD>
<TITLE>File Download Program Thing</TITLE>
<SCRIPT LANGUAGE="Javascript">
/* Javascript Code Here */
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#000000" TEXT="#FFFFFF">
<FORM NAME="linkfrm" ACTION="$this">
<CENTER>
<H1>Choose A File</H1>
<HR><BR>
PAGE

foreach $file (@files) {
$frnt = substr($file, 0, 3);
if ($buscode eq $frnt) {
print "<A HREF="$this?
getfile=$file&path=$cpath">$file</A><BR>
";
}
}
print <<PAGE1;
</CENTER>
</FORM>
</BODY>
</HTML>
PAGE1

}

sub load_type_list
{
# /* You Can Modify Everything Below print <<PAGE;, but stop
BEFORE PAGE */
# print header;
print <<PAGE;
<HTML>
<HEAD>
<TITLE>File Download Program Thing</TITLE>
<SCRIPT LANGUAGE="Javascript">
/* Javascript Code Here */
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#000000" TEXT="#FFFFFF">
<FORM NAME="fnamefrm" METHOD="POST" ACTION="$this">
<CENTER>
<H1>Please Choose File Type</H1>
<HR><BR>
PAGE

print "<SELECT NAME="fname">
";
foreach $fn (@fnames) {
print "<OPTION VALUE="$fn">$fn</OPTION>
";
}
print "</SELECT>
";
print <<PAGE1;
<INPUT TYPE="HIDDEN" NAME="uname" VALUE="$username">
<INPUT TYPE="HIDDEN" NAME="pass" VALUE="$password">
<INPUT TYPE="HIDDEN" NAME="bcode" VALUE="$buscode">
<INPUT TYPE="SUBMIT" VALUE="Choose">
</CENTER>
</FORM>
</BODY>
</HTML>
PAGE1
}

sub auth_failure
{

# /* You Can Modify Everything Below print <<PAGE;, but stop
BEFORE PAGE */
print header;
print <<PAGE;
<HTML>
<HEAD>
<TITLE>File Download Program Thing</TITLE>
<SCRIPT LANGUAGE="Javascript">
/* Javascript Code Here */
function chk_fields()
{
uname =
document.loginfrm.uname.value;
pass = document.loginfrm.pass.value;

if (uname == "") {
alert("I Need A Username");
return false;
}

if (pass = "") {
alert("I Need A Password");
return false;
}

document.loginfrm.submit();
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#000000" TEXT="#FFFFFF">
<FORM NAME="loginfrm" ACTION="$this">
<CENTER>
<H1>Invalid Login</H1>
<HR><BR>
<B>Username</B><BR>
<INPUT TYPE="TEXT"
NAME="uname"><BR><BR>
<B>Password</B><BR>
<INPUT TYPE="PASSWORD"
NAME="pass"><BR><BR>
<INPUT TYPE="HIDDEN" NAME="cmd"
VALUE="auth">
<INPUT TYPE="BUTTON" VALUE="Login"
onClick="chk_fields();">
<INPUT TYPE="BUTTON" VALUE="Cancel"
onClick="history.go(-2);"><BR>
</CENTER>
</FORM>
</BODY>
</HTML>
PAGE
&foot;
}

sub get_file_list
{
$dirpath = shift;
system("/bin/ls -AF1 $dirpath >>ffile");
open(FH, "< ffile") or die "I suck";
while (<FH>) {
chomp($_);
$lchr = substr($_, length($_) -1);
if ($lchr ne "/") {
/(.*)/s;
push @filelist, $1;
}
}
close(FH);
unlink "ffile";

return @filelist;
}


sub authenticate
{
chomp($uname = param(`uname`));
chomp($pass = param(`pass`));

open(FH, "$passfile");
while (<FH>) {
chomp($_);
($tlogin, $tpasswd, $tbcode) = split(/ /,
$_);
push @logins, $tlogin;
push @passwds, $tpasswd;
push @bcodes, $tbcode;
}
close(FH);


$cnt = 0;
$flag = "false";
foreach $lname (@logins) {
if ($lname eq $uname) {
if ($passwds[$cnt] eq $pass) {
$hld = $cnt;
$flag = "true";
}
}
$cnt++;
}

if ($flag eq "false") {
# /* User Failed Authentication */
&auth_failure;
} else {
$username = $logins[$hld];
$password = $passwds[$hld];
$buscode = $bcodes[$hld];
$outcookie = $cgi->cookie(-name=>`buscode`, -
value=>`auth`, -path=>`/`);
print header(-cookie=>$outcookie);
}
}

sub foot
{
print end_html;
die;
}

sub bitch
{
print header, start_html;
print "<CENTER>
";
print h1("Not Enough Data"), hr, br;
print "</CENTER>
";
print end_html;
die;
}
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help