-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftp_spider.php
47 lines (40 loc) · 1.36 KB
/
ftp_spider.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
<?php
set_time_limit(0);
// $con = ftp_connect("192.168.56.11");
// $login = ftp_login($con, "duola", "duola123");
$con = ftp_connect("ftp3.ouc.edu.cn");
$login = ftp_login($con, "Anonymous", "");
$myfile=fopen("result.txt","w");
$queue = array("/"); //存放目录的队列
while(!empty($queue)){ //还有未遍历目录
$list_now = array_shift($queue);//本次处理目录
// if(!ftp_chdir($con, $list_now)){//文件目录不存在,数字开头后加空格的奇葩命名文件
// fwrite($myfile, $list_now."\r\n");
// continue;//跳过本次循环
// }
ftp_chdir($con, $list_now);
$filelist = ftp_rawlist($con, $list_now);
$name = preg_replace("/.+:*\\d+\\s/", "", $filelist[2]);
if(count($filelist) == 3 && ftp_size($con, $name) != -1){
//只有一个电影,目录名字即为电影名
fwrite($myfile, $list_now."\r\n");
}else{
foreach($filelist as $file)
{
$filename = preg_replace("/.+:*\\d+\\s/", "", $file);
if(ftp_size($con, $filename) == -1){
//是目录
if($filename != "." && $filename != ".."){
array_push($queue, $list_now."/".$filename);
//echo "<br>\ndocument:".$list_now."/".$filename;
}
}
else{
fwrite($myfile, $list_now."/".$filename."\r\n");
}
}
}
}
fclose($myfile);
ftp_close($con);
?>