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:
Problem connecting to the ftp server

 



chander1986
Novice

Jun 2, 2009, 9:56 AM

Post #1 of 3 (239 views)
Problem connecting to the ftp server Can't Post

I have the following code through which i am connecting to some ftp server:

my $ftp = Net::FTP->new(HOST) or die "Couldn't connect :$@\n";


The problem is, if the ftp server is busy, the code dies giving the error message.

Is there a way where i can put it in a loop and try to connect until the connection is successful?

The simplest thing would be :

if cant connect then wait for say 10seconds and try to reconnect .This should continue for say 10 attempts.If it cant connect even after 10 attempts then the program should die.

Is there a way to do it in PERL ??


1arryb
User

Jun 2, 2009, 10:50 AM

Post #2 of 3 (235 views)
Re: [chander1986] Problem connecting to the ftp server [In reply to] Can't Post

Hi chander,

Sure:

Code
... 
my $host = "somehost.somedomain";
my $ftp;
for (my $try = 0; $try < 10; $try++) {
$ftp = NET::FTP->new($host);
last if $ftp;
sleep 10;
}
die "no connection after 10 tries" unless $ftp;
...


Cheers,

Larry


chander1986
Novice

Jun 2, 2009, 11:12 AM

Post #3 of 3 (233 views)
Re: [1arryb] Problem connecting to the ftp server [In reply to] Can't Post

Thanks a lot. :)

 
 


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

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