-
Notifications
You must be signed in to change notification settings - Fork 3
/
collect4k.pl
executable file
·65 lines (54 loc) · 1.76 KB
/
collect4k.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
###
## Copyright (c) 2012, Chris Rushton
##
## Permission to use, copy, modify, and distribute this software for any
## purpose with or without fee is hereby granted, provided that the above
## copyright notice and this permission notice appear in all copies.
##
## THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
## WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
## ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
## ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
## OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
###
use Net::FTP;
$host = $ARGV[0];
$user = $ARGV[1];
$pass = $ARGV[2];
if (($#ARGV+1) != 3) {
print "Please enter a hostname.\n";
print "Example: collect4k.pl <hostname> <user> <pass>\n";
exit 1;
}
$ftp=Net::FTP->new($host, Passive=>1, Timeout=>240) or $newerr=1;
push @ERRORS, "Can't ftp to $host: $!\n" if $newerr;
myerr() if $newerr;
$ftp->login($user,$pass) or $newerr=1;
push @ERRORS, "Can't login to $host: $!\n" if $newerr;
$ftp->quit if $newerr;
myerr() if $newerr;
$ftp->cwd('/ramdrv/logs') or $newerr=1;
push @ERRORS, "Can't change directory to /ramdrv/logs: $!\n" if $newerr;
myerr() if $newerr;
@files=$ftp->ls or $newerr=1;
push @ERRORS, "Cant list directory: $!\n" if $newerr;
myerr() if $newerr;
foreach(@files) {
print "Getting $_...";
if ($ftp->get($_)) {
print "OK\n";
}else {
$newerr=1;
push @ERRORS, "Couldn't get $_ $!\n" if $newerr;
}
}
$ftp->quit;
myerr() if $newerr;
sub myerr {
print "Error: \n";
print @ERRORS;
exit 0;
}