-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathftp-get.php
More file actions
141 lines (114 loc) · 4.26 KB
/
Copy pathftp-get.php
File metadata and controls
141 lines (114 loc) · 4.26 KB
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
133
134
135
136
137
138
139
140
141
<?php
// Kutsutaanko CLI:stä
$php_cli = FALSE;
if (php_sapi_name() == 'cli') {
$php_cli = TRUE;
}
date_default_timezone_set('Europe/Helsinki');
if ($php_cli) {
ini_set("include_path", ini_get("include_path").PATH_SEPARATOR.dirname(__FILE__).PATH_SEPARATOR."/usr/share/pear");
error_reporting(E_ALL ^E_WARNING ^E_NOTICE);
ini_set("display_errors", 0);
require "inc/salasanat.php";
require "inc/functions.inc";
// Logitetaan ajo
cron_log();
if (!isset($ftpget_email)) $ftpget_email = "development@devlab.fi"; // kenelle meilataan jos on ongelma
if (!isset($ftpget_emailfrom)) $ftpget_emailfrom = "development@devlab.fi"; // millä osoitteella meili lähetetään
// ja operaattori komentoriviltä
// itella, servinet, yms
// pitää olla määritettynä salasanat.inc:issä tai sitten tämä menee puihin.
$operaattori = $argv[1];
}
// Sallitaan vain yksi instanssi tästä skriptistä kerrallaan
pupesoft_flock();
if ($operaattori == "") {
mail($ftpget_email, mb_encode_mimeheader("VIRHE: FTP-get!", "ISO-8859-1", "Q"), "FTP-get sisäänluvussa ongelma, ei operaattoria valittuna. Tutki asia!", "From: ".mb_encode_mimeheader("Pupesoft", "ISO-8859-1", "Q")." <$ftpget_emailfrom>\n", "-f $ftpget_emailfrom");
exit;
}
if ($ftpget_host[$operaattori] != '' and $ftpget_user[$operaattori] != '' and $ftpget_pass[$operaattori] != '' and $ftpget_path[$operaattori] != '' and $ftpget_dest[$operaattori] != '') {
if (isset($ftpget_port[$operaattori]) and (int) $ftpget_port[$operaattori] > 0) {
$ftpget_port[$operaattori] = (int) $ftpget_port[$operaattori];
$conn_id = ftp_connect($ftpget_host[$operaattori], $ftpget_port[$operaattori]);
}
else {
$conn_id = ftp_connect($ftpget_host[$operaattori]);
}
// jos connectio ok, kokeillaan loginata
if ($conn_id) {
$login_result = ftp_login($conn_id, $ftpget_user[$operaattori], $ftpget_pass[$operaattori]);
}
if ($login_result) {
$changedir = ftp_chdir($conn_id, $ftpget_path[$operaattori]);
}
// haetaan filet active modella
if ($changedir) {
if (!isset($ftpget_ei_passive) or trim($ftpget_ei_passive) == '') {
ftp_pasv($conn_id, true);
}
$files = ftp_nlist($conn_id, ".");
if ($files) {
foreach ($files as $file) {
if (isset($ftpget_filt[$operaattori]) and $ftpget_filt[$operaattori] != "") {
// Skipataan ne tiedostot joissa ei ole määriteltyä stringiä nimessä
if (stripos($file, $ftpget_filt[$operaattori]) === FALSE) {
continue;
}
}
$temp_filename = tempnam("/tmp", "ftp");
$fileget = ftp_get($conn_id, $temp_filename, $file, FTP_ASCII);
if (filesize($temp_filename) == 0) {
// echo "VIRHE: Ladattava tiedosto on tyhjä!\n";
unlink($temp_filename);
}
elseif ($fileget) {
rename($temp_filename, $ftpget_dest[$operaattori]."/".$file);
ftp_delete($conn_id, $file);
}
else {
echo "VIRHE: Tiedoston $file lataus epaonnistui!\n";
unlink($temp_filename);
}
}
}
}
if ($conn_id) {
ftp_close($conn_id);
}
$palautus = 0;
// mikä feilas?
if ($conn_id === FALSE) {
$palautus = 1;
}
if ($login_result === FALSE) {
$palautus = 2;
}
if ($changedir === FALSE) {
$palautus = 3;
}
if ($files === FALSE) {
$palautus = 4;
}
// jos siirto epäonnistuu
if ($palautus != 0) {
switch ($palautus) {
case 1:
$syy = "Could not connect to remote host. ($ftpget_host[$operaattori])";
break;
case 2:
$syy = "Could not login to remote host ($conn_id, $ftpget_user[$operaattori], $ftpget_pass[$operaattori])";
break;
case 3:
$syy = "Changedir failed ($conn_id, $ftpget_path[$operaattori], ".realpath($ftpget_path[$operaattori]).")";
break;
case 4:
$syy = "Getting files failed ($conn_id, $ftpget_path[$operaattori])";
break;
default:
$syy = t("Tuntematon errorkoodi")." ($palautus)!!";
}
}
}
else {
mail($ftpget_email, mb_encode_mimeheader("VIRHE: FTP-get!", "ISO-8859-1", "Q"), "FTP-get sisäänluvussa saattaa olla ongelma. Jokin tarvittavista tiedoista on väärin (operaattori: $operaattori)", "From: ".mb_encode_mimeheader("Pupesoft", "ISO-8859-1", "Q")." <$ftpget_emailfrom>\n", "-f $ftpget_emailfrom");
}