-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathftp-spider.php
executable file
·67 lines (51 loc) · 1.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/php
<?php
/*
* FTP Spider
* Wogan May
*/
require_once("ftp-spider-functions.php");
$Options = ftpspider_options();
if (!$Options) {
stdout("Not all required parameters were provided - at the very least, set the host.");
die("\n");
}
debug("Starting FTP Spider run");
debug("Connecting to: ".$Options['host']);
$connection = ftp_connect($Options['host']);
if (!$connection) {
stdout("Error while trying to connect to the specified host");
die("Terminating\n");
} else {
// If username and password are set, try logging in
if ($Options['username'] && $Options['password']) {
$login_result = ftp_login($connection, $Options['username'], $Options['password']);
} else {
// Anonymous login
$login_result = ftp_login($connection, "anonymous", "");
}
if (!$login_result) {
stdout("Error while trying to log into the specified FTP server", 'time');
die("Terminating\n");
} else {
debug("Connected to host");
}
}
// Let's do some stuff!
$MasterList = array();
$gNav = array();
ftpspider_recurse($connection, "/");
debug("Discovered ".count($MasterList)." files");
if ($Options['outputlinks']) {
// Use ftp://USER:PASS@HOST{LINK}
foreach($MasterList as $link) {
echo sprintf("ftp://%s:%s@%s%s\n", $Options['username'], $Options['password'], $Options['host'], $link);
}
} else {
// Just dump the link
foreach($MasterList as $link) {
echo "$link\n";
}
}
debug("Disconnecting from host");
ftp_close($connection);