CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
why ?my CGI code can't use FTP module!

 



tack
Novice

Jul 30, 2003, 8:37 PM

Post #1 of 19 (4205 views)
why ?my CGI code can't use FTP module! Can't Post

following is my code :


Code

  

#!/usr/bin/perl

use Net::FTP;
my $file="E:\\server\\Apache\\htdocs\\111\\time.txt";
$ftp=Net::FTP->new("tack.smice.net",timeout=>30);
$ftp->login($user,"$password);
$ftp->put($file,"tt.txt");

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




it can runs on dos , but not on IE browser .is it wrong ? help!




(This post was edited by tack on Jul 30, 2003, 8:39 PM)


davorg
Thaumaturge / Moderator

Jul 31, 2003, 1:23 AM

Post #2 of 19 (4202 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post


In Reply To
following is my code :

Code
#!/usr/bin/perl 
use Net::FTP;
my $file="E:\\server\\Apache\\htdocs\\111\\time.txt";
$ftp=Net::FTP->new("tack.smice.net",timeout=>30);
$ftp->login($user,"$password);
$ftp->put($file,"tt.txt");
print "content-type:text/html\n\n";


it can runs on dos , but not on IE browser .is it wrong ? help!


In what way does it fail to work? What unexpected behaviour areyou seeing? Are you getting any error messages? Is there anything in the web server error log?

It's always a good idea to have "use strict" and "use warnings" in your Perl code as they can help you find several common problems.

A couple of things I've spotted:

1/ You have an unnecessary double quote in the line

Code
$ftp->login($user,"$password);

Either remove it, or add another one to match it.

2/ Your content-type header is wrong. You should probably use the "header" function from CGI.pm to ensure that you get it right.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


tack
Novice

Jul 31, 2003, 5:31 AM

Post #3 of 19 (4198 views)
Re: [davorg] why ?my CGI code can't use FTP module! [In reply to] Can't Post

yes , the double quote is clerical error. And i try to use CGI module this time . The code becomes:


Code
   

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use Net::FTP;
my $file="E:\\server\\Apache\\htdocs\\111\\time.txt";
my $ftp=Net::FTP->new("tack.smice.net",timeout=>30);
$ftp->login($user,$password);
$ftp->put($file,"tt.txt");

my $html = new CGI;
print $html->header;



but the problem hasn't been resolved. IE sent me this message:"ERROR 500: INTERNAL SERVER ERROR".I think it is server error . because the code could run on DOS, but not IE. But i don't know what I should do about the server to resolve this problem. could you help me more? Thanks!


(This post was edited by tack on Jul 31, 2003, 5:33 AM)


davorg
Thaumaturge / Moderator

Jul 31, 2003, 5:57 AM

Post #4 of 19 (4192 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

If you get an "Internal Server Error" message then the real error message will almost certainly be written to the web server error log. Why not try looking there?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Jane
Novice

Jul 31, 2003, 3:23 PM

Post #5 of 19 (4186 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

You can get some error messages from CGI::Carp. Type the following under the line 'use CGI;'


Code
   

use CGI::Carp qw( fatalsToBrowser );



Run your program and come back here with the message.

The error is not coming from your browser, it's coming from your server software. Ensure that

-path to Perl is correct.

-the modules you want to use are installed.

-the file name stored in $file exists.


Jane.
Think |negatively :(|
map{$,--%(5>>1)^0?push@y,$_:unshift@y,$_}sort(Hacker=>another=>Perl=>Just);for(1&1=>1|0){push@y,shift@y}print"@y";


(This post was edited by Jane on Jul 31, 2003, 3:25 PM)


tack
Novice

Aug 14, 2003, 12:58 PM

Post #6 of 19 (4162 views)
Re: [davorg] why ?my CGI code can't use FTP module! [In reply to] Can't Post


Code
  

[Fri Aug 15 03:49:01 2003] [error] [client 218.14.109.29] Premature end of script headers: e:/server/apache/htdocs/hack/try.pl
[Fri Aug 15 03:49:01 2003] [error] [client 218.14.109.29] Can't locate Net/FTP.pm in @INC (@INC contains: e:/usr/lib e:/usr/site/lib .) at e:\server\apache\htdocs\hack\try.pl line 5.

[Fri Aug 15 03:49:01 2003] [error] [client 218.14.109.29] BEGIN failed--compilation aborted at e:\server\apache\htdocs\hack\try.pl line 5.



it is "error.log" . how should i do now? i ensure there is ftp module in my computer. and the same code can run on "cmd.exe". but it can't run as cgi. Unsure


KevinR
Veteran


Aug 14, 2003, 5:45 PM

Post #7 of 19 (4157 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

your code does contain an error, you are using strict but you have not packaged $user and $password with my
-------------------------------------------------


(This post was edited by KevinR on Aug 14, 2003, 5:46 PM)


tack
Novice

Aug 14, 2003, 11:50 PM

Post #8 of 19 (4149 views)
Re: [KevinR] why ?my CGI code can't use FTP module! [In reply to] Can't Post

actually, there is no "$user" and "$password" in my code , i just replaced real username and password with them . the code actually like this:

$ftp->login("hello","hello");

so i think the problem is not "use strict"


Jasmine
Administrator / Moderator

Aug 15, 2003, 4:53 PM

Post #9 of 19 (4136 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

The problem is that you don't have Net::FTP installed.

You should install Net::FTP to fix the problem. If you're using ActivePerl, type install libnet at the ppm prompt.


tack
Novice

Aug 15, 2003, 6:59 PM

Post #10 of 19 (4132 views)
Re: [Jasmine] why ?my CGI code can't use FTP module! [In reply to] Can't Post

if i didn't hava Net::FTP installed , why could it run on dos(cmd.exe)

i don't know why the server can't find it.


(This post was edited by tack on Aug 15, 2003, 7:00 PM)


Jasmine
Administrator / Moderator

Aug 16, 2003, 2:52 AM

Post #11 of 19 (4127 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post


Quote
if i didn't hava Net::FTP installed , why could it run on dos(cmd.exe)

Because the dos ftp program is different from Net::FTP. You'll need to install a ftp wrapper (which is what Net::FTP is, loosely).


tack
Novice

Aug 16, 2003, 6:50 AM

Post #12 of 19 (4122 views)
Re: [Jasmine] why ?my CGI code can't use FTP module! [In reply to] Can't Post


In Reply To
Because the dos ftp program is different from Net::FTP. You'll need to install a ftp wrapper (which is what Net::FTP is, loosely).



I didn't use the dos ftp tool. following is my code run on dos :


Code
>perl try.pl  

cotent-Type:html/text;charset=ISO-8859-1



and my file had transported to the destination successfully.(but failed on browser)

does i really need to install other module in addition? thanks


Jasmine
Administrator / Moderator

Aug 16, 2003, 9:33 AM

Post #13 of 19 (4119 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

Didn't realize that it worked when you tried it on the command line. If you copy/pasted what you get when you type perl try.pl, then the problem looks to be

cotent-Type:html/text;charset=ISO-8859-1

it should be content, not cotent


KevinR
Veteran


Aug 16, 2003, 10:19 AM

Post #14 of 19 (4117 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

I'm just offering a suggestion, try printing the http header earlier in the script:



#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use Net::FTP;
my $html = new CGI;
print $html->header;


my $file="E:\\server\\Apache\\htdocs\\111\\time.txt";
my $ftp=Net::FTP->new("tack.smice.net",timeout=>30);
$ftp->login('hello','hello');
$ftp->put($file,"tt.txt");




see if that helps anything.
-------------------------------------------------


tack
Novice

Aug 16, 2003, 5:21 PM

Post #15 of 19 (4112 views)
Re: [Jasmine] why ?my CGI code can't use FTP module! [In reply to] Can't Post


In Reply To
Didn't realize that it worked when you tried it on the command line. If you copy/pasted what you get when you type perl try.pl, then the problem looks to be

cotent-Type:html/text;charset=ISO-8859-1

it should be content, not cotent



oh, i am sorry. That was my clerical error . it was content , not cotent for real.


tack
Novice

Aug 16, 2003, 5:28 PM

Post #16 of 19 (4111 views)
Re: [KevinR] why ?my CGI code can't use FTP module! [In reply to] Can't Post

i have executed your code . but it changed nothing , the server error was still there.

Is there any security setting limitting cgi to use FTP?


KevinR
Veteran


Aug 17, 2003, 11:57 AM

Post #17 of 19 (4103 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post

I am sure the server can be setup to not accept ftp transfers, but that is not your problem, the problem is your script is crashing, and it looks like because it can not locate the FTP module, but you say it is installed.
-------------------------------------------------


davorg
Thaumaturge / Moderator

Aug 18, 2003, 1:12 AM

Post #18 of 19 (4099 views)
Re: [tack] why ?my CGI code can't use FTP module! [In reply to] Can't Post


In Reply To
if i didn't hava Net::FTP installed , why could it run on dos(cmd.exe)

i don't know why the server can't find it.


The problem is probably that there are two versions of Perl installed. When you're running from the command line you are using one version of Perl (which does have Net::FTP installed in its library of modules) but when you're running from the web server it's using another version which doesn't have Net::FTP installed.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


tack
Novice

Aug 18, 2003, 6:33 AM

Post #19 of 19 (4093 views)
Re: [davorg] why ?my CGI code can't use FTP module! [In reply to] Can't Post

thanks all perlers upstair . it is Ok now , it is really there are two versions of perl in my computer as same as davorg said.

i am sorry for my carelessness. thanks all here.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives