Hello Builders ;-)
I've the trouble with FTP-client script.
I use fsockopen for connection.
the problem in severals FTP-servers.
Some servers return 150 Opening ASCII mode data connection for file list on LIST request - but some 125 Data connection already open; Transfer starting.
My script works fine then code 150 received from server.
When code 125 received script cannot get data through DataConnection.
Some info from documentation:
125 Data Connection already open, transfer starting.
150 File status okay, about to open data connection. FTP uses two ports: 21 for sending commands, and 20 for sending data. A status code of 150 indicates that the server is about to open a new connection on port 20 to send some data.
Before sending LIST command to server I've opened DataConnection to server.
When server answer 150 - I read list of files and all fine. But when code is 125 - no data received from DataConnection. Return is empty (not false!, no errors).
FTP-server works fine through FTP-programs. But not through my script.
My questions:
1. Why server returns
125 Data connection already open; Transfer starting.
226 Transfer complete.
on my ONE request? 226 Transfer complete. returns in one moment with 125 code.
2. Why no data through DataConnection from server.
Anybody works with FTP through fsockopen? Can you help me?
Some code
Command sending:
if($Cmd) if(!@fputs($this->CmdSocket, $Cmd . "\r\n")) {$Error = 'Connect lost'; return false;}
sleep(1);
if(!$Error = trim(@fread($this->CmdSocket, 4096))) {$Error = 'No answer'; return false;}
return substr($Error,0,3)
Get LIST:
if($this->doCmd('TYPE A') != '200') return false;
if($this->doCmd('PASV') != '227') return false;
if(!$this->connect_data()) return false; // start DataConnection
$ListCmd = $this->doCmd('LIST ' . $this->Dir);
if($ListCmd != '150' and $ListCmd != '125') return false;
if(($Data = $this->read()) === false) return false; // Empty answer
return explode("\n", $Data);