sub sendFile {
# application object
my $self = shift;
# create an ftp object
my $ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21) or die "Cannot connect to host: $@";
# login to the ftp server
$ftp->login("user",'pass') or die $ftp->message;
# get root directory
$ftp->cwd() or die $ftp->message;
# get the filename
my $filename = "dir+filename";
# check if file exist
if(-e $filename){
# send file in binary mode
$ftp->binary;
# send a file to the remote server
$ftp->put($filename) or die $ftp->message;
}
# quit the ftp connection
$ftp->quit;
# output
return $tmpl->output;
}
sub deleteFile {
# application object
my $self = shift;
# create an ftp object
my $ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21) or die "Cannot connect to host: $@";
# login to the ftp server
$ftp->login("user",'pass') or die $ftp->message;
# get root directory
$ftp->cwd() or die $ftp->message;
# get the filename
my $filename = "filename";
# delete a file to the remote server
$ftp->delete($filename);
# quit the ftp connection
$ftp->quit;
# output
return $tmpl->output;
}
sub sendFile {
# application object
my $self = shift;
# load template files
my $tmpl = $self->param('info' => $self->load_tmpl('info.phtml'));
...
}
Re: your question of where the bug is, I think it's here:
# get the filename
my $filename = "dir+filename";
# check if file exist
if(-e $filename){
-- Burvil
-- Burvil
Error executing run mode 'send_file': Cannot connect to host: Net::FTP: connect: timeout at /home/domains/xxx/www.xxx.com/aa/system/modules//FTP.pm line 16. at /home/domains/xxx/www.xxx.com/aa/index.cgi line 20as well as the fact that it's happening 3/4 times makes me think that there's some sort of network connectivity issues. To isolate and confirm this,
use Carp;
....
my $ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21, => Timeout => 300) or
croak "Cannot connect to host: $@";
Note that I used croak instead of die, which will give you more verbose information.
my $ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21, => Timeout => 300);
my $num_tries = 0;
my $max_tries = 5 #you decide how many times you want to try
while ( !$ftp) {
if ($num_tries< $max_tries) ) {
++$num_tries;
$ftp = Net::FTP->new("XXX.XX.XX.XXX", Debug => 1, Port => 21, => Timeout => 300);
}
if ($num_tries >= $max_tries) ) {
croak "Cannot connect to host, failed after $num_tries times : $@";
}
}
-- Burvil
ssh prompt: netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg Warning: cannot open /proc/net/dev (Permission denied). Limited output. missing interface information: Permission deniedI tried to higher to timeout value but it will still timeout. If it doesn't work right away, it's not going to work. However, I am calling these subroutines from links in a html page. If I click a link an nothing happens within approx. 2 seconds, I click it again and again. eventually it will work. It might be on the second, third or ninth try..., but it will finally connect
No luck with the loop either, same problem.
While waiting for the timeout error, I used ping on the windows server with the following result:
148 packets transmitted, 148 packets received, 0% packet loss round-trip min/avg/max = 0.2/0.2/0.3 ms
perlmonks.org content © perlmonks.org and boboson, bowei_99
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03