in reply to i want to go through the code of Net::Ftp module in perl

Net::FTP has a default timeout of 120 seconds, but you can override the timeout in the constructor:
my $ftp = Net::FTP->new("some.host.name", Timeout => 50) or die "Cannot connect to some.host.name: $@";

I pretty much copied this literally from the perl documentation, which you can access on a system with perl correctly installed with

perldoc Net::FTP
I only replaced the 'Debug' option, which, now that I think about it, might be a pretty good idea too. Options can be specified in the constructor as
my $ftp = Net::FTP -> ("some.host.com", Debug => 1, Timeout => 50, Option => value, Option => value ...);