Skip to main content
Inspiring
September 2, 2009
Question

Flex FTP and socket error #2031

  • September 2, 2009
  • 3 replies
  • 12718 views

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>

    This topic has been closed for replies.

    3 replies

    Participating Frequently
    February 11, 2010

    Luke,

    I am able to connect to my FTP server and my code is very similar to yours. Could you try once by creating a local FTP server? This way we can be sure that it is no network/firewall issue.

    Participating Frequently
    February 10, 2010

    Partner in crime

    read this

    http://tech.groups.yahoo.com/group/flexcoders/messages/72018?threaded=1&m=e&var=1&tidx=1

    it simply says that there is a certain limitation with Flex sockets and to fix that some modification to the application protocol is required.

    Inspiring
    February 10, 2010

    Thanks, I've just read the tread. Pretty intersting.

    They say a lot about transfering huge amoung of data, but our problem reside in establishing the connection.

    For creating the application I used the FlexFTP library of Maliboo but it crash as well my own plain code.

    I read over the internet the the socket class lacks of many functionality, maybe they gotta improve a little bit more.

    I would like to try with flex4

    ASAP I'll post the wireshark log. I did it in the past but I didn't save it!!!

    Good bye!!

    Keep on fighting against socket!!!

    Have a nice day!

    Luke

    Participating Frequently
    October 20, 2010

    I had the exact same issue and same symptoms. However I was lucky that I had control over the hosting server and firewall server. I got it working by:

    1. Login to the hosting server and modify pureFTP to only open ports from range 45000-50000
    2. Login to the firewall server that's protecting the hosting server and added a allow port range 45000-50000 from any source
    3. Run the AS FTP client and it worked nicely!

    Hope that helps you. I also tried Wireshark, but the responses were very similar between filezilla and the Flash FTP client. Still don't know how filezilla does it, but the above worked for me 100% of the time.

    Good luck in solving your issue!

    leybniz
    Participating Frequently
    September 2, 2009

    How many different FTP servers have you used to try out this? for me it seems problem in the FTP server side..

    Inspiring
    September 3, 2009

    First, thanks for your reply!

    I've first tried on the main hosting platform we use and doesn't work.

    This morning I've also tried on another low-cost hosting platofrm and it works quite well (I can get to make the data connection in passive mode and retrieve the file list).

    The weird thing is  that since our main hosting platform has changed the server the flex ftp doesn't work anymoe. Before, all worked well.

    If is a problem of FTP server which colud be the cause?

    Could be due to a wrong configuration?Some firewall?

    Another strange thing is that other FTP client such Fetch or FileZilla connects well without any problem.Maybe flex socket lack of something?

    Below some information about the server (this is the FileZilla log):

    220---------- Welcome to Pure-FTPd [TLS] ----------

    [...]

    SYST
          215 UNIX Type: L8

    FEAT
         211-Extensions supported:
          EPRT
         IDLE
         MDTM
         SIZE
         REST STREAM
          MLST type*;size*;sizd*;modify*;UNIX.mode*;UNIX.uid*;UNIX.gid*;unique*;    
          MLSD

         ESTP
         PASV
          EPSV
          SPSV
          ESTA
          AUTH TLS
          PBSZ
         PROT

    Let me Know!!!

    Best regards!

    leybniz
    Participating Frequently
    September 3, 2009

    fetch feature sets from both FTP servers and compare them to eliminate the possible difference.

    also please mark helpful posts to ease up others to find same looking solutions faster, thanks.