2 Replies Latest reply on Aug 7, 2009 5:39 AM by molocco

    FTP Problem

    molocco

      Hi all,

       

      I'm doing a basic ftp client in AIR, and I'm having some problems.

       

      Code:

      private function start(account:FtpAccountVO):void 
      {
           connect(account);
           this.userName(account.username);
           this.passWord(account.password);
           this.changeDirectory(account.directory);
           sendCommand("PASV");
      }
      private function connect(account:FtpAccountVO):void
      {
           socket = new Socket(account.server, account.port);
           socket.addEventListener(ProgressEvent.SOCKET_DATA, receiveReply);
           socket.addEventListener(IOErrorEvent.IO_ERROR, showError);
           socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, showSecError);
           socket.addEventListener(Event.CONNECT, onSocketConnect);
           socket.addEventListener(Event.CLOSE, onSocketClose);
           socket.addEventListener(Event.ACTIVATE, onSocketActivate);
      }
      
      private function receiveReply(e:ProgressEvent):void
      {
           ftpResponse = socket.readUTFBytes(socket.bytesAvailable)
           var serverResponse:Number = Number(ftpResponse.substr(0, 3));
           trace(ftpResponse);
           if (ftpResponse.indexOf("227") > -1)
           {
                var match:Array = ftpResponse.match(/(\d{1,3},){5}\d{1,3}/);
                if (match != null)
                {
                     var data:Array = match[0].split(",");
                     dataChannelIP = data.slice(0, 4).join(".");
                     dataChannelPort = parseInt(data[4]) * 256 + parseInt(data[5]);
                     dataChannelSocket = new Socket();
                     dataChannelSocket.addEventListener(ProgressEvent.SOCKET_DATA, receiveData);
                     dataChannelSocket.addEventListener(IOErrorEvent.IO_ERROR, showError);
                     dataChannelSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, showSecError);
                     dataChannelSocket.connect(dataChannelIP, dataChannelPort);
                }
           }
      }
      
      private function receiveData(e:ProgressEvent):void
      {
           dataResponse = dataChannelSocket.readUTFBytes(dataChannelSocket.bytesAvailable);
           trace(dataResponse);
      }
      

       

      And, I'm getting:

       

      Error #2031: Socket Error. URL: 76.12.57.106
      Error #2048: Security sandbox violation: app:/app.swf cannot load data from 
      *.*.*.*:*.
      

       

      Any idea?

       

      Thanks in advance,

      Greetings!.

        • 1. Re: FTP Problem
          Gregory Lafrance Level 6

          I think you need a crossdomain.xml file.

           

          SWF can only load data from the same domain unless a crossdomain.xml file is setup.

           

          mySub.myCompany.com   is considered a different domain from     www.myCompany.com

           

          Also verify menubar Project - Properties - Flex Compiler - Additional compiler arguments has    -use-network=true

           

          If this post answered your question or helped, please mark it as such.

          1 person found this helpful
          • 2. Re: FTP Problem
            molocco Level 1

            I understand but, How is possible that I have to put a crossdomain file on each ftp site that I want to access? if I'm codding a ftp client, I want that the user just put the ftp data and "connect", without download another client, then put the crossdomain file, and then connect with the air client...

             

            Is it the only way?

             

            Thanks in advance.