-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathupload_cache.php
66 lines (51 loc) · 1.66 KB
/
upload_cache.php
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
<?php
defined('APP_STARTED') or die('Direct call is not allowed');
require_once __DIR__ . '/vendor/autoload.php';
require_once 'config.php';
if (empty($serverUpload)) {
return;
}
echo "\n**************************\n";
echo "starting result upload\n";
// ftp connect
$conn_id = ftp_connect($serverUpload['host']);
$login_result = ftp_login($conn_id, $serverUpload['user'], $serverUpload['password']);
ftp_pasv($conn_id, true);
if ((!$conn_id) || (!$login_result)) {
exit('FTP login failed');
}
$files = ['result_communities.json', 'result_routers.json', 'result_statistics.json'];
// uploading all files as filename.json.staging
foreach ($files as $fileName) {
echo 'uploading: '.$fileName."\n";
$fp = fopen(__DIR__.'/cache/'.$fileName, 'r');
if (ftp_fput($conn_id, $fileName.'.staging', $fp, FTP_TEXT)) {
echo "Successfully uploaded $fileName\n";
} else {
echo "There was a problem while uploading $fileName\n";
}
echo 'upload done'."\n";
}
$fileList = ftp_rawlist($conn_id, '/');
// renaming all filename.json.staging to filename.json
foreach ($files as $fileName) {
echo 'renaming: "'.$fileName.'.staging" to "'.$fileName.'"'."\n";
if (in_array($fileName, $fileList)) {
// file already exists - delete the old one before renaming new
if (!ftp_delete($fileName)) {
echo 'delete failed for: ' . $fileName . "\n";
continue;
}
}
if (!ftp_rename(
$conn_id,
$fileName.'.staging',
$fileName
)) {
echo 'rename failed for: '.$fileName."\n";
continue;
}
echo 'rename done'."\n";
}
// close the connection
ftp_close($conn_id);