6 Einträge, 1 Seite |
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print qq~
<html>
<head>
<meta http-equiv="refresh" content="900">
</head>
<body>~;
use Net::FTP;
my $host="host";
my $directory="html";
my $counter_file = 'cam.csv';
my $lock_file = 'cam.lock';
my $lock_dir = 'cam_lock';
my $count;
my $flock_support = 1;
if ($flock_support == 0) {
&lock_file;
if (-e $counter_file) {
open (COUNTER_FILE,"+<$counter_file") or die "Kann $counter_file nicht öffnen: $!\n";
}
}else {
if (-e $counter_file) {
open (COUNTER_FILE,"+<$counter_file") or die "Kann $counter_file nicht öffnen: $!\n";
flock(COUNTER_FILE,2) or die "Can file nicht sichern: $!\n";
}
}
#------------------------------------------------------------------------------------------
--
$count = <COUNTER_FILE>;
chop $count;
close(COUNTER_FILE);
$count++;
if (-e $counter_file) {
open (COUNTER_FILE,">$counter_file") or die "Kann $counter_file nicht öffnen: $!\n";
flock(COUNTER_FILE,2) if $flock_support or die "Can file nicht sichern: $!\n";
}
print (COUNTER_FILE "$count;");
close(COUNTER_FILE);
#------------------------------------------------------------------------------------------
--
if($flock_support == 0) {
close(COUNTER_FILE);
&unlock_file;
}else { close(COUNTER_FILE); }
$ftp=Net::FTP->new($host,Timeout=>240) or $newerr=1;
push @ERRORS, "Can't ftp to $host: $!\n<br>" if $newerr;
myerr() if $newerr;
print $ftp->message;
print "<br>";
$ftp->login("usn","pwd") or $newerr=1;
print "Getting file list<br>";
push @ERRORS, "Can't login to $host: $!\n<br>" if $newerr;
$ftp->quit if $newerr;
myerr() if $newerr;
print $ftp->message;
print "<br>";
$ftp->cwd($directory) or $newerr=1;
push @ERRORS, "Can't cd $!\n<br>" if $newerr;
myerr() if $newerr;
print $ftp->message;
print "<br>";
$ftp->quit if $newerr;
@files=$ftp->dir or $newerr=1;
push @ERRORS, "Can't get file list $!\n<br>" if $newerr;
myerr() if $newerr;
print $ftp->message;
print "<br>";
#foreach(@files) {
# print "$_\n<br>";
#}
$ftp->binary();
$ftp->get('cam.jpg',"cam_$count.jpg") or $newerr=1;
push @ERRORS, "Can't get file $!\n<br>" if $newerr;
myerr() if $newerr;
print $ftp->message;
print "<br>";
$ftp->quit;
print "Closed FTP<br>";
print qq~$count Bilder downloaded
</body>
</html>~;
sub lock_file {
my $lock_timeout = 60;
my $lock_count;
while(-f $lock_file && !mkdir($lock_dir,0777)) {
if (++$lock_count > $lock_timeout) {
die("Kann \"$lock_file\" nicht sichern!: $!\n");
return 1;
}
sleep (1);
}
open(LOCK,">$lock_file") || die("Can't open $lock_file: $!\n");
return 0;
}
sub unlock_file {
close(LOCK);
unlink("$lock_file");
rmdir($lock_dir);
}
sub myerr {
print "Error: \n";
print @ERRORS;
exit 0;
}
1
2
3
4
use FindBin;
my $counter_file = $FindBin::Bin . '/cam.csv';
my $lock_file = $FindBin::Bin . '/cam.lock';
my $lock_dir = $FindBin::Bin . '/cam_lock';
6 Einträge, 1 Seite |