Flex FTP and socket error #2031
Hi to all!
I'm trying to develop a FTP client in Flex/Air with socket (...whatelse
!?!?)
I can connect to the FTP server and authenticate. Then I switch to passive mode sending the "PASV" ftp command.
In response i receive the data port on which I will (...well...actually....on which I would like to....
) transfer the files. And here comew the trouble.
I create a new socket wich attempts to connect on the port the server told me, it stands still for some moments and give me the socket error #2031.
Below the complete error (URL's IP replaced with 'xx.xx.xx.xx'):
[IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Socket Error URL: xx.xx.xx.xx" errorID=2031]
I've tried to google around but i didn't find anything useful more than Adobe Flex Socket reference (which doesn't even talk about #2031 error
)
I've also tried to perform FTP task with the maliboo FTP lib but it behaves the same as mentioned before.
Any ideas,suggestions or solutions?
Thanks in advance guys for the attention!
Best regards!
Luca
P.S. :
Below the code I've used:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical" initialize="init()">
<mx:Script>
<![CDATA[
private var sCommand:Socket
private var sData:Socket
private function init():void{
sCommand=new Socket("xx.xx.xx.xx",21);
sCommand.addEventListener(ProgressEvent.SOCKET_DATA,commandResponse)
sCommand.addEventListener(IOErrorEvent.IO_ERROR, commandError);
sCommand.writeUTFBytes("USER xxxxxx\n");
sCommand.flush();
sCommand.writeUTFBytes("PASS xxxxxxx\n");
sCommand.flush();
sCommand.writeUTFBytes("CWD /mydirectory/\n");
sCommand.flush();
sCommand.writeUTFBytes("PASV\n");
sCommand.flush();
}
private function commandResponse(e:ProgressEvent):void{
var command_resp:String=sCommand.readUTFBytes(sCommand.bytesAvailable)
if(command_resp.indexOf("227")>-1){
var temp:String = command_resp.substring(command_resp.indexOf("(")+1,command_resp.indexOf(")"));
var data_channel_temp:Array = temp.split(",");
var data_channel_ip:String=data_channel_temp.slice(0,4).join('.')
var data_channel_port:int=parseInt(data_channel_temp[4])*256+parseInt(data_channel_temp[5])
trace(data_channel_ip+" "+data_channel_port)
sData=new Socket(data_channel_ip,data_channel_port) //here it starts to stand still and after a while it crash with error #2031
sData.addEventListener(ProgressEvent.SOCKET_DATA,dataResponse)
sData.addEventListener(IOErrorEvent.IO_ERROR, dataError);
}
trace("command "+command_resp)
}
private function commandError(e:IOErrorEvent):void{
trace("command -> "+e.text)
}
private function dataResponse(e:ProgressEvent):void{
trace('data '+e)
}
private function dataError(e:IOErrorEvent):void{
trace('data error ' +e)
}
]]>
</mx:Script>
</mx:WindowedApplication>
