##################################################### # Purpose: CONSTRUCTOR ##################################################### # Here load default values sub new { my $class = shift; my $self = {}; my $f = ftpdata->new(); ## set general ftpdata area - undef the rest $f->retries(20); $f->mode(1); ## default to ascii - 1 $f->sleeptime(120); $f->servers(0,"151.1.152.11"); $f->servers(1,"151.1.152.15"); ## this sets the data to the object $self->{FTPDATA} = $f;
bless($self,$class); return $self; }
##################################################### # Purpose: DESTRUCTOR ##################################################### # sub DESTROY { my $self = shift; $self->logoff(); }
##################################################### # Purpose: Method to return saved data structure ##################################################### # sub ftpdata { my $self = shift; return $self->{FTPDATA}; }
sub setDebugLevel { ##################################################### # Purpose: Method to set the debug level ##################################################### # Accept Parameters # my $self = shift; my ($r) = @_; ## this line retrieves the structure my $f = $self->ftpdata(); ## this line sets the parm in the data structure $f->debug($r);
return "OK"; }
sub setPort { ##################################################### # Purpose: Method to set the port ##################################################### # Accept Parameters # my $self = shift; my ($r) = @_; my $f = $self->ftpdata(); $f->port($r); return "OK"; }
sub setPassiveON { ##################################################### # Purpose: Method to set Passive mode ##################################################### # Accept Parameters # my $self = shift; my $f = $self->ftpdata(); $f->passive(1); return "OK"; }
sub setPassiveOFF { ##################################################### # Purpose: Method to set active mode ##################################################### # Accept Parameters # my $self = shift; my $f = $self->ftpdata(); $f->passive(0); return "OK"; }
sub setTimeOut { ##################################################### # Purpose: Method to set timeout ##################################################### # Accept Parameters # my $self = shift; my ($r) = @_; my $f = $self->ftpdata(); $f->timeout($r); return "OK"; }
sub setRetries { ##################################################### # Purpose: Method to set retries ##################################################### # Accept Parameters # my $self = shift; my ($r) = @_; my $f = $self->ftpdata(); $f->retries($r); return "OK"; }
sub setSleepTime { ##################################################### # Purpose: Method to set sleep between connection try ##################################################### # Accept Parameters # my $self = shift; my ($r) = @_; my $f = $self->ftpdata(); $f->sleeptime($r); return "OK"; }
sub setModeBinary { ##################################################### # Purpose: Method to set Mode Binary ##################################################### # my $self = shift; my $f = $self->ftpdata(); $f->mode(2); return "OK"; }
sub setModeAscii { ##################################################### # Purpose: Method to set Mode Ascii ##################################################### # my $self = shift; my $f = $self->ftpdata(); $f->mode(1); return "OK"; }
##################################################### # Purpose: Method to logoff from connection ##################################################### # sub logoff { my $rc; my $self = shift;
## retrieve the object for the code to operate on my $f = $self->ftpdata(); ## set local variable with the ftp object my $ftp = $f->ftp;
if ($ftp) { $rc=$ftp->quit; } $f->ftp(undef); }
##################################################### # Purpose: Method to connect to a server in list ##################################################### # sub connect { my $self = shift; my $tryAgain = 1; my %args; my $ftp; ## retrieve the private vars my $f = $self->ftpdata(); ### set local vars as necessary my $retries = $f->retries; my @s = $f->servers; my @servers = @{$s[0]}; my $stime = $f->sleeptime;
### build any arguments for connection undef %args; if ( $f->timeout ) { $args { 'TIMEOUT' } = $f->timeout; } if ( $f->passive ) { $args { 'PASSIVE' } = $f->passive; } if ( $f->port ) { $args { 'PORT' } = $f->port; } if ( $f->debug ) { $args { 'DEBUG' } = $f->debug; } while($retries) { foreach my $s (@servers) { if ($ftp = Net::FTP->new($s,%args)) { $f->connection($s); $f->ftp($ftp); return "OK"; } } $retries--; sleep $stime;