FTP Class (myftp.php)
<?php
Class Myftp {
var $connector;
var $getback;
Function Connect ($ftp _server, $uname, $passwd) {
Baut Grundlegende FTP Connection auf
$this->connector = @ftp_connect ($ftp _server);
$this->login_result = @ftp_login ($this->connector, "$uname", "$passwd");
if (! $this->connector) ││ (! $this->login_result))
{
echo "FTP Connection has failed! n ";
echo "Attempted to connect to $ftp _server for user $uname n";
Die
} else {
echo "Connected to $ftp _server, for user $uname n";
}
}
function Lastmodtime ($value) {
$getback = Ftp_mdtm ($this->connector, $value);
return $getback;
}
function Changedir ($targetdir) {
$getback = Ftp_chdir ($this->connector, $targetdir);
return $getback;
}
function Getdir () {
$getback = ftp_pwd ($this->connector);
return $getback;
}
function Get_file_list ($directory) {
$getback = Ftp_nlist ($this->connector, $directory);
return $getback;
}
function Get_file ($file _to_get, $mode, $mode 2) {
$realfile = basename ($file _to_get);
$filename = $realfile;
$checkdir = @ $this->changedir ($realfile);
if ($checkdir = = TRUE) {
Ftp_cdup ($this->connector);
echo "N[dir] $realfile";
}else{
echo "..... ". $realfile. " n ";
$getback = Ftp_get ($this->connector, $filename, $realfile, $mode);
if ($mode 2) {
$delstatus = Ftp_delete ($this->connector, $file _to_get);
if ($delstatus = = TRUE) {
echo "File $realfile on $host deleted n";
}
}
}
return $getback;
}
function mode ($pasvmode) {
$result = FTP_PASV ($this->connector, $pasvmode);
}
function Ftp_bye () {
Ftp_quit ($this->connector);
return $getback;
}
}
?>
<?php
Flush ();
$ftp _ini_datei = $argv [1];
Require ('./ftp_class.php ');
Require ($ftp _ini_datei);
echo "Ncronjob started:";
echo Date ("D.m.y-h:i:s");
echo "n";
$newftp = new Myftp;
if (! $anonymous) {
$result = $newftp->connect ($host, $user, $password);
}else{
$result = $newftp->connect ($host, "Anonymous", "mymail@somewhere.com");
}
if (! $result) {
$mydir = $newftp->changedir ($remote _dir);
$mydir = $newftp->getdir ();
$merkold _dir = GETCWD ();
ChDir ($local _dir);
$mylist = Array ();
$mylist = $newftp->get_file_list ($mydir);
for ($i =0; $i < sizeof ($mylist); $i + +)
{
$result = $newftp->get_file ($mylist [$i], $mymode, $delete);
}
$result = $newftp->ftp_bye ();
}else{
echo "----------------------------------n";
echo "No connection established:(n";
echo "----------------------------------n";
}
echo "Nncronjob stopped:";
echo Date ("D.m.y-h:i:s");
echo "n";
?>