#!/usr/local/bin/perl -w
#
###################################################################################
# Script using FTP for backup of /etc/hosts and /tftpboot
#
# Christian SCHLEGEL - 24.11.2000
# 24.01.2001 Con
# 
###################################################################################

use strict;
use Net::Ping;					# Use Module Net::Ping
use Net::FTP;					# USe Module Net::FTP

my $ftp_server = "FTP-Server";			# name of the FTP-server
my $ftp_user = "username";			# username for the FTP-access
my $ftp_pass = "password";			# password for the FTP-access

my $path_date;					# name (with path!) of the tranferring file
my $date;					# date used as a prefix for the transfered 
						# file
my $year;					# year
my $mon;					# month
my $day;					# day

my $ftp_conn = Net::FTP->new($ftp_server);
						# definitions for the FTP-connection

$year = (localtime)[5]+1900;			# extract the actual year
$mon  = (localtime)[4]+1;			# extract the actual month
$day  = (localtime)[3];				# extract the actual day
if ($mon < 10) {$mon = "0".$mon}		# two digits for the month
if ($day < 10) {$day = "0".$day}		# two digits for the day
$date = $year.$mon.$day;				# set the actual date

$ftp_conn->login($ftp_user, $ftp_pass);		# Login on the FTP-Server
$ftp_conn->type("I");				# define "binary" for transmission

						# tranfer /etc/hosts
$ftp_conn->cwd("/system/etc");
$ftp_conn->put("/etc/hosts", "hosts$date");

						# transfer all files in /tftpboot/al
$ftp_conn->cwd("/system/tftpboot/al");
while (defined($path_date = </tftpboot/al/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/al/alt
$ftp_conn->cwd("/system/tftpboot/al/alt");
while (defined($path_date = </tftpboot/al/alt/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/al/r
$ftp_conn->cwd("/system/tftpboot/r");
while (defined($path_date = </tftpboot/r/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/r/ios
$ftp_conn->cwd("/system/tftpboot/r/ios");
while (defined($path_date = </tftpboot/r/ios/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/r/old
$ftp_conn->cwd("/system/tftpboot/r");
while (defined($path_date = </tftpboot/r/old/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/route
$ftp_conn->cwd("/system/tftpboot/route");
while (defined($path_date = </tftpboot/route/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/wc
$ftp_conn->cwd("/system/tftpboot/wc");
while (defined($path_date = </tftpboot/wc/*>)) {
	$ftp_conn->put("$path_date");
}

						# transfer all files in /tftpboot/ws
$ftp_conn->cwd("/system/tftpboot/ws");
while (defined($path_date = </tftpboot/ws/*>)) {
	$ftp_conn->put("$path_date");
}

$ftp_conn->quit;				# disconnect from  FTP-server

=head1 NAME

ftp_backup.pl

=head1 VERSION

1.0

=head1 SYNOPSIS

ftp_backup.pl

=head1 DESCRIPTION

=head1 ARGUMENTS

=head1 EXAMPLE

=head1 AUTHOR

Christian Schlegel
