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:
Got a mind-boggeling problem... (FTP-error)

 



Peter Van Hoecke
Deleted

Apr 28, 2000, 1:56 AM

Post #1 of 4 (610 views)
Got a mind-boggeling problem... (FTP-error) Can't Post

I wrote a script that does some FTP, and I want to create seperate loops for retries and so. This piece of code does it's work, bnut I get this error message (if I try to connect to a server that exists, but is put ofline):

C:\scripts\putstats>perl putstats.pl 1
Try number 0...oedjemul, 200, 15
Net::FTP: Unknown error at putstats.pl line 139
Try number 1...oedjemul, 200, 15
Net::FTP: Unknown error at putstats.pl line 139
Try number 2...oedjemul, 200, 15
Net::FTP: Unknown error at putstats.pl line 139


here is the troublemaking code ($ftp = Net::FTP->new... is the line 139)

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>



TRYCONNECT:
while( $FTPdie && ($tries <= $retries))
{
print("\t\tTry number $tries...$hostName, $hostPort, $timeoutSecs\n");
($ftp && $ftp->quit); # if I'm trying for the second, third,... time I have to destroy the $ftp object
$tries++;
$ftp = Net::FTP->new( $hostName, Port => $hostPort, Timeout => $timeoutSecs)
| | (($tries != $retries) && (sleep 5 && next TRYCONNECT))
| | &HandleError("Can not connect to <$sourceHost>: Host not reachable!\n" )
};
</pre><HR></BLOCKQUOTE>

[This message has been edited by Peter Van Hoecke (edited 04-28-2000).]

[This message has been edited by Peter Van Hoecke (edited 04-28-2000).]


gvh
Deleted

Apr 28, 2000, 2:42 AM

Post #2 of 4 (610 views)
Re: Got a mind-boggeling problem... (FTP-error) [In reply to] Can't Post

This maybe a typo, but the &#0124; &#0124; bars in the
posted script have a space between them:
this certainly prevents them from being
interpreted correctly.


Peter Van Hoecke
Deleted

Apr 28, 2000, 2:54 AM

Post #3 of 4 (610 views)
Re: Got a mind-boggeling problem... (FTP-error) [In reply to] Can't Post

Hmm... it is a typo in my message...

Sadly enough I don't have the typo in my script... I have corrected the code in the forum.

hint:

In the HTML about FTP there is a line:

"If the constructor fails undef will be returned and an error message will be in $@"

and $@ is the perl syntax error message from the last eval command. Perhaps I just can't intercept these problems, but in that case there must be a way to tell Perl that it has to ignore this eval?

Anyone? ... I'm hurting badly here...



[This message has been edited by Peter Van Hoecke (edited 04-28-2000).]


gvh
Deleted

Apr 28, 2000, 12:07 PM

Post #4 of 4 (610 views)
Re: Got a mind-boggeling problem... (FTP-error) [In reply to] Can't Post

I tried to fill in the missing bits so that the script could be tried. I had to use an imaginary host name, but I suppose that this does not have any effect on the problem:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#! perl -w

use strict;
use Net::FTP;

my $FTPdie = 1; # the loop doesn't change it, so I suppose it is true;
my $ftp;
my $tries = 1;
my $hostName = 'silly.imaginary.host';
my $hostPort = '1234';

my $timeoutSecs = 10;
my $retries = 10;

TRYCONNECT:
while( $FTPdie && ($tries <= $retries))
{
print("\t\tTry number $tries...$hostName, $hostPort, $timeoutSecs\n");
($ftp && $ftp->quit); # if I'm trying for the second, third,... time I have to destroy the $ftp object
$tries++;
$ftp = Net::FTP->new( $hostName, Port => $hostPort, Timeout => $timeoutSecs)
&#0124; &#0124; (($tries != $retries) && (sleep 5 && next TRYCONNECT))
&#0124; &#0124; &HandleError("Can not connect to <$hostName>: Host not reachable!\n" )
};

# connect was successsfull
# put or get whatever
$ftp->quit; # close remote connection

sub HandleError {
my ( $msg ) = @_;
die $msg;
}

</pre><HR></BLOCKQUOTE>

I did not find any problem with this script:


Code
                Try number 1...silly.imaginary.host, 1234, 10 
Try number 2...silly.imaginary.host, 1234, 10
Try number 3...silly.imaginary.host, 1234, 10
Try number 4...silly.imaginary.host, 1234, 10
Try number 5...silly.imaginary.host, 1234, 10
Try number 6...silly.imaginary.host, 1234, 10
Try number 7...silly.imaginary.host, 1234, 10
Try number 8...silly.imaginary.host, 1234, 10
Try number 9...silly.imaginary.host, 1234, 10
Can not connect to <silly.imaginary.host>: Host not reachable!
{/CODE]

Sorry I couldn't reproduce the error.

 
 


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

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