Files

145 lines
2.4 KiB
PHP
Raw Permalink Normal View History

<?php
// Original code: The Wizard of DATz
2016-02-25 21:35:52 -08:00
// Use this to replace drive calls
2016-03-01 00:00:44 -08:00
$server = "grandis.nu";
$resource = ftp_connect($server) or die("Couldn't connect to ".$server);
if (!ftp_login($resource, "ftp", "any"))
{
die("Could not log in to ".$server);
}
2016-02-25 21:35:52 -08:00
$dirs = array(
'Atari',
2016-03-01 00:00:44 -08:00
// 'Commodore_Amiga',
// 'Commodore_C128',
// 'Commodore_C16,_C116_&_Plus-4',
// 'Commodore_C64',
// 'Commodore_C65',
// 'Commodore_MAX_Machine_&_VIC10',
// 'Commodore_PET',
// 'Commodore_VIC20',
);
$skip_query = implode('', file("../sites/".$source."_skip.txt"));
$skip_query = explode("\n", "\n".$skip_query);
$skip_query = array_flip($skip_query);
$search_ok = true;
print "<pre>check folders:\n\n";
foreach ($dirs as $dir)
{
if ($search_ok && $dir)
{
listDir($dir);
}
}
2016-03-01 00:00:44 -08:00
ftp_close($resource);
if ($search_ok)
{
2016-03-01 00:00:44 -08:00
/*
$fp = fopen("../sites/".$source."_skip.txt", "w");
fwrite($fp, "");
fclose($fp);
2016-03-01 00:00:44 -08:00
*/
}
print "\nnew urls:\n\n";
foreach($found as $url)
{
print "<a href=\"ftp://ftp:amiga@grandis.nu/".str_replace('#', '%23', $url[0])."\">".$url[1]."</a>\n";
}
function listDir($dir)
{
sleep(1);
2016-03-01 00:00:44 -08:00
GLOBAL $r_query, $found, $skip_query, $search_ok, $resource;
print "open: ".$dir."\n";
$other = 0;
$new = 0;
$old = 0;
$folder = 0;
2016-03-01 00:00:44 -08:00
if(!ftp_chdir($resource, $dir))
{
$search_ok = false;
}
else
{
2016-03-01 00:00:44 -08:00
$pwd = ftp_pwd($resource);
$files = ftp_nlist($resource, $pwd);
foreach ($files as $file)
{
2016-03-01 00:00:44 -08:00
// If the file already exists, skip it
if ($r_query[$file])
{
2016-03-01 00:00:44 -08:00
//print "found old: ".$file."\n";
$old++;
}
2016-03-01 00:00:44 -08:00
// Otherwise, either add it to the list or go into the new directory
else
{
2016-03-01 00:00:44 -08:00
// If the item is a directory, move into it and parse
if (is_ftp_dir($file))
{
2016-03-01 00:00:44 -08:00
$folder++;
if (!$skip_query[$file])
{
2016-03-01 00:00:44 -08:00
listDir($file);
}
2016-03-01 00:00:44 -08:00
else
{
2016-03-01 00:00:44 -08:00
print "skip: ".$file."\n";
}
}
2016-03-01 00:00:44 -08:00
// Otherwise, it's a file that should be checked
else
{
2016-03-01 00:00:44 -08:00
print "found: ".$file."\n";
$found[] = $file;
$new++;
die();
}
}
}
}
if ($search_ok)
{
print "close: ".$dir."\n";
print "new: ".$new.", old: ".$old.", folder:".$folder."\n";
2016-03-01 00:00:44 -08:00
/*
$fp = fopen("../sites/".$source."_skip.txt", "a");
fwrite($fp, $dir."\n");
fclose($fp);
2016-03-01 00:00:44 -08:00
*/
}
}
2016-03-01 00:00:44 -08:00
function is_ftp_dir($dirname)
2016-02-25 21:35:52 -08:00
{
2016-03-01 00:00:44 -08:00
GLOBAL $resource;
$pwd = ftp_pwd($resource);
if (@ftp_chdir($resource, $dirname))
2016-02-25 21:35:52 -08:00
{
2016-03-01 00:00:44 -08:00
ftp_chdir($resource, $pwd);
return true;
}
else
{
return false;
2016-02-25 21:35:52 -08:00
}
}
?>