-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ftp_list.php
executable file
·81 lines (63 loc) · 1.79 KB
/
get_ftp_list.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
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/php
<?php
include('config.php');
include('function.php');
include('ftp.class.php');
include('pclzip.lib.php');
$result = get_ftp_content(FTP_FILE, STORAGE_TARGET);
if($result === false || !file_exists(STORAGE_TARGET)){
access_log('log', 'Download FTP file FAIL.');
exit();
}
access_log('log', 'Download FTP file OK.');
$current_path = dirname(__FILE__);
$extract_path = $current_path .'/upload/';
if(!extract_zip(STORAGE_TARGET, $extract_path)){
access_log('log', 'ZIP extract fail.');
exit();
}
if(!file_exists($extract_path)){
access_log('log', 'No file.');
exit();
}
access_log('log', 'Obtain file.');
function extract_zip($target, $extract_path) {
$zip = new PclZip($target);
if ($zip->extract(PCLZIP_OPT_PATH, $extract_path) == 0) {
return false;
} else {
return true;
}
}
function get_ftp_content($source, $target) {
$result = false;
$config = array(
'hostname' => FTP_HOST,
'username' => FTP_USER,
'password' => FTP_PASSWORD,
'port' => FTP_PORT,
'timeout' => FTP_TIMEOUT
);
$ftp = new Ftp();
$ftp->connect($config);
if($ftp->existsFile($source)){
$result = $ftp->download($source, $target);
}else{
access_log('log', 'No documents.');
//clear_file();
}
$ftp->close();
return $result;
}
function clear_file(){
if(file_exists(STORAGE_TARGET)){
$log = (unlink(STORAGE_TARGET)) ?'ZIP delete SUCCESS.' : 'ZIP delete FAIL.';
access_log('log', $log);
}
$current_path = dirname(__FILE__);
$extract_file = $current_path .'/upload/test.txt';
if(file_exists($extract_file)){
$log = (unlink($extract_file)) ?'TXT delete SUCCESS.' : 'TXT delete FAIL.';
access_log('log', $log);
}
}