some improve ftp class

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.3.1@10936 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2012-07-24 09:12:18 +00:00
parent 8a1f88ddf8
commit cf1f7dec90

View file

@ -80,6 +80,12 @@
$this->ftp_debug("Error : fsockopen() ".$errstr." (".$errno.")\n");
return FALSE;
}
if(substr($this->ftp_resp, 0, 3) !== '220')
{
return FALSE;
}
$this->ftp_debug("Connected to remote host \"".$server.":".$port."\"\n");
return TRUE;
@ -477,10 +483,43 @@
function ftp_ok()
{
$this->ftp_resp = "";
do {
$res = fgets($this->ftp_sock, 512);
$this->ftp_resp .= $res;
} while (substr($res, 3, 1) != " ");
// 한줄을 읽는다.
$line = '';
while(($char = fgetc($this->ftp_sock)) !== FALSE)
{
$line .= $char;
if($char === "\n") break;
}
// 세자리 응답 코드가 나와야 한다.
if(!preg_match('@^[0-9]{3}@', $line))
{
return FALSE;
}
$this->ftp_resp = $line;
// 4번째 문자가 -이면 여러줄인 응답이다.
if($line[3] === '-')
{
$code = substr($line, 0, 3);
// 한줄 단위로 읽어 나간다.
do
{
$line = '';
while(($char = fgetc($this->ftp_sock)) !== FALSE)
{
$line .= $char;
if($char === "\n") break;
}
$this->ftp_resp .= $line;
// 응답 코드와 같은 코드가 나오고 공백이 있으면 끝
if($code . ' ' === substr($line, 0, 4)) break;
}while($line);
}
$this->ftp_debug(str_replace("\r\n", "\n", $this->ftp_resp));