padawan_linuxero has asked for the wisdom of the Perl Monks concerning the following question:
Where in this program I can use reconnect or how to use it? thanks!use Net::FTP; use strict; { my $pollingInterval = 1; my $directoryToMonitor = "C:/testdir"; my %oldFileList = (); my %currentFileList = (); # we start by getting the file list, considered to be the "old" list # getFileList($directoryToMonitor, \%oldFileList); for (;;) { sleep($pollingInterval); # get the current file list and compare it to the old file list # if the lists differ, the current file list becomes the old file +list # and we FTP the files # getFileList($directoryToMonitor, \%currentFileList); if ( fileListsDiffer(\%oldFileList, \%currentFileList) ) { copyFileList(\%oldFileList, \%currentFileList); #dumpFileList(\%oldFileList); # the FTP commands should go here instead of the dumpFileList() +function above my @transferFileList = glob "m*.*"; my @fileList = glob "m*.*"; foreach my $file (@fileList) { chomp($file); if ( $file =~ /.+\.\d{1,}/ ) { # one or more characters, a '.' foll +owed by one or more digits print "Iniciando transmision de datos...\n"; print STDOUT "<Nombre valido del Archivo>" . $file . "\n"; my $filesize = -s $file; print "Size: $filesize\n"; my $server = "124.32.54.59"; my $username = "saai"; my $pass = "saaisi0"; my $ftp; print "Connecting to $server..\n"; # Set up connection $ftp = Net::FTP->new( $server, Passive => 1, Debug => 0 ) o +r die $@; print "..authenticating..\n"; # Log in... $ftp->login( $username, $pass ) or die $ftp->message; print "..done!\n"; $ftp->cwd('Envio') or die $ftp->message; print "Directorio actual es :\n"; print $ftp->pwd (), "\n"; $ftp->ascii(); $ftp->put("$file") or die $ftp->message; my $tamano = $ftp->size($file); print "el tamano del archivo es : $tamano\n"; print "Comprobando el envio de los archivos\n"; if ($filesize = $tamano) { print "\nSON DEL MISMO TAMANO\n"; } else { print "ooooopppssss!!!! intentando enviarlo de nuevo"; } print "Logging out.."; #or die $ftp->message; $ftp->quit; print "..done!\n\n\n"; } else { print STDOUT "<Nombre Invalido del Archivo> " . $file . "\n\n\n"; } } for (@transferFileList) { #print "$_\n"; system ("del",$_); } } } } # Basically prints the contents of a hash. # sub dumpFileList { my $list = shift; my @k = sort(keys(%$list)); for (my $i=0; $i<=$#k; $i++) { print $k[$i] . " " . $list->{$k[$i]} . "\n"; } print "\n"; } # Get a list of the files along with there modification times # from the specified directory. The results are place in the # specified hash where the key is the file name and the value # is that file's modification time. # sub getFileList { my $directory = shift; my $hash = shift; %$hash = (); opendir(DIR,$directory) || die "Can not open $directory"; my @files = grep(!/^\.\.?$/, readdir(DIR)); closedir(DIR); for (my $i=0; $i<=$#files; $i++) { $hash->{$files[$i]} = (stat("$directory/$files[$i]"))[9]; } } # See if two hashes of files differ. The hashes are considered differ +ent if one of the # following occurrs: # # 1. The hashes have different number of elements. # 2. The new hash is missing a key that is in the old hash. # 3. For a given key, the value in the old hash differs from the val +ue in the new hash. # sub fileListsDiffer { my $oldList = shift; my $newList = shift; my @oldKeys = (keys(%$oldList)); my @newKeys = (keys(%$newList)); if ($#newKeys != $#oldKeys) { return 1; } foreach my $key (@oldKeys) { if ( ! defined($newList->{$key}) || $newList->{$key} ne $oldList-> +{$key} ) { return 1; } } return 0; } # Copies one hash to another. The destination has ($to below) is empt +ied first. # sub copyFileList { my $to = shift; my $from = shift; %$to = (); foreach my $key (keys(%$from)) { $to->{$key} = $from->{$key}; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to implement Net::FTP::AutoReconnect
by webfiend (Vicar) on Apr 21, 2008 at 20:03 UTC | |
|
Re: how to implement Net::FTP::AutoReconnect
by samtregar (Abbot) on Apr 21, 2008 at 20:06 UTC | |
|
Re: how to implement Net::FTP::AutoReconnect
by apl (Monsignor) on Apr 21, 2008 at 20:03 UTC | |
|
Re: how to implement Net::FTP::AutoReconnect
by sgifford (Prior) on Apr 22, 2008 at 04:56 UTC |