$needvers[$i]) break;
if (($vers[$i]+0)<$needvers[$i]) {
$this->ConnectError(4);
return 4;
}
}
$this->Disconnect();
if (strlen($server)) {
if (preg_match('/[^0-9.]/',$server)) {
$ip=gethostbyname($server);
if ($ip==$server) {
$ip='';
$rv=2;
}
} else $ip=$server;
} else $ip='127.0.0.1';
if (strlen($ip)) {
if ($this->fp=@fsockopen($ip,21)) {
$this->Sleep();
$this->GetResponse($n,$t);
if ($n==220) {
$this->DoCommand("user $user",$n,$t);
if ($n==331) $this->DoCommand("pass $pass",$n,$t);
if ($n!=230) $rv=3;
} else $rv=1;
} else $rv=1;
}
if ($rv) $this->ConnectError($rv);
return $rv;
}
function Disconnect($exit=1) {
if ($this->fp) {
if ($exit) $this->DoCommand('quit',$j1,$j2);
fclose($this->fp);
$this->fp=NULL;
}
}
function DoCommand($c,&$rn,&$rt) {
$rn=0;
$rt='';
if ($this->fp) {
fputs($this->fp,"$c\r\n");
$this->Sleep();
$this->GetResponse($rn,$rt);
}
return $this->fp?1:0;
}
function GetResponse(&$rn,&$rt) {
$more=1;
$rn=0;
$rt='';
do {
$l=preg_replace("/[\r\n]+/",' ',fread($this->fp,5000));
if (preg_match('/^([0-9]{3})( |-)(.*)$/',$l,$m)) {
$rn=$m[1]+0;
$rt.=$m[3];
if ($m[2]==' ') $more=0;
} else $rt.=$l;
$s=socket_get_status($this->fp);
} while ($more&&$s['unread_bytes']);
$rt=trim($rt);
}
function Sleep() {
if ($this->use_usleep) usleep($this->sleeptime);
else sleep(1);
}
function ConnectError($num) {
if ($this->show_connect_error) switch ($num) {
case 1: echo '
[PHP FTP] Connect failed: Unable to open network connection
'; break;
case 2: echo '
[PHP FTP] Connect failed: Unknown host
'; break;
case 3: echo '
[PHP FTP] Connect failed: Login failed
'; break;
case 4: echo '
[PHP FTP] Connect failed: Your server\'s PHP version is too low for PHP FTP
'; break;
}
}
}
?>