sockets - PHP's ftp_raw function with MLSD and fsockopen: weird blocking behaviour and Warning messages -
i'm having problem ftp's ftp_raw function.
i need precise , verbose list of files , directories of ftp directory (ftp_rawlist not precise enough datetimes , not specified). want use more normalized command: mlsd.
i list of files want, after getting data socket, impossible use php's ftp* functions anymore...
here extract of code:
//current folder = "/" $directory = "/www/"; $currentfolder = ftp_pwd($ftpstream); echo $currentfolder; echo ' : '; ftp_chdir($ftpstream, $directory); $ret = ftp_raw($ftpstream, 'pasv'); if (preg_match('#^227.*\(([0-9]+,[0-9]+,[0-9]+,[0-9]+),([0-9]+),([0-9]+)\)$#', $ret[0], $matches)) { $controlip = str_replace(',', '.', $matches[1]); $controlport = intval($matches[2]) * 256 + intval($matches[3]); $socket = fsockopen($controlip, $controlport); ftp_raw($ftpstream, 'mlsd'); $s = ''; while (!feof($socket)) { $s .= fread($socket, 4096); } fclose($socket); } echo ftp_pwd($ftpstream); //line 256 echo ' --> '; ftp_chdir($ftpstream, $currentfolder); //line 258 echo ftp_pwd($ftpstream); //line 260 displays :
/ : <br /> <b>warning</b>: ftp_pwd(): transfer complete. in <b>/media/sf_web/x/webservice/models/ftp.class.php</b> on line <b>256</b><br /> --><br /> <b>warning</b>: ftp_chdir(): "/www" current directory. in <b>/media/sf_web/x/webservice/models/ftp.class.php</b> on line <b>258</b><br /> <br /> <b>warning</b>: ftp_pwd(): cwd command successful. in <b>/media/sf_web/x/webservice/models/ftp.class.php</b> on line <b>260</b><br /> errors not consistent then.
for information, if comment whole "if" conditional block, normal behaviour, no warning:
/ : /www --> / */ where mistake? how explain incoherent warning messages , impossibility use correctly $ftpstream after that?
i've been looking solution hours, appreciated... :)
thank in advance.
the mlsd, ftp data transfer commands, issues multiple responses.
typically 1 or more 1xx preliminary replies, like
150 opening data channel directory listing of "/path" and 1 final response, in case:
226 transfer complete. the ftp_raw function reads 1 response, i.e. prelimirary 150 one. keeping final 226 response "in queue".
once issue new ftp command, i.e. pwd, finds pending 226 response, , stops on that.
the actual pwd response again left "in queue":
257 /www current directory. and on.
you warnings because status codes not match commands. positive response pwd 257, not 226. positive response cwd 250, not 257, etc.
i'm afraid there's no way in sync there's no php function skip/read ftp reply.
so option disconnect , connect again.
Comments
Post a Comment