Skip navigation
Currently Being Moderated

FTP client problem

Jan 5, 2010 5:24 AM

Hello.

I'm trying to create a ftp client running on adobe AIR in flex builder.

The fcommand socket work, but when i create the data socket, the command socket still work but if I tipe a new command, like PWD, i do not receive answer. Does someone know why?

I don't see error events widh IO_ERROR or SECURITY error, so I suppose no error occours.

 

here is the code

 

import flash.events.Event;
               import flash.events.IOErrorEvent;
               import flash.events.MouseEvent;
               import flash.events.ProgressEvent;
               import flash.events.SecurityErrorEvent;
               import flash.net.Socket;
 
               protected var s:Socket;               // socket comandi
               protected var s_dati:Socket;
               protected function btn_connetti_clickHandler(event:MouseEvent):void
               {
                    var aspetta:Boolean = true;
                    
                    function connesso(evt:Event):void     {
                         //label_stato.text += "Connesso!";
                         
                         // ora che la socket è connessa invia user e password
                         s.writeUTFBytes("USER **\n");
                         s.writeUTFBytes("PASS **\n");
                         
                         // apre un canale dati passivo
                         //s.writeUTFBytes("RETR index.php\n");
                         s.writeUTFBytes("PASV\n");
                    }
                    
                    function connessoDati(evt:Event):void     {
                         label_stato.text += "Socket dati connessa!";
                         
                         if(s.connected)
                              s.writeUTFBytes("\nLIST\n\n");     THIS COMMAND DOES NOT RETURN ANY OUTPUT
                         else
                              label_stato.text = "CONNESSIONE PERSA\n";
                    }
                    
                    function riceviDati(evt:ProgressEvent):void     {
                         label_stato.text += "DATA -> "+ s_dati.readUTFBytes(evt.bytesLoaded);
                    }
                    
                    function erroreSicurezza(evt:SecurityErrorEvent):void     {
                         label_stato.text = "Errore nella sicurezza "+evt.text;
                    }
                    
                    function chudi(evt:Event):void     {
                         label_stato.text = "Chiusura connessione";
                    }
                    
                    function progresso(evt:ProgressEvent):void     {
                         var str:String = s.readUTFBytes(evt.bytesLoaded);
                         label_stato.text += str;
                         var arrS:Array = str.split("\n");
                         for (var i:int = 0; i<arrS.length; i++)     {
                              //if(arrS[i])
                              //label_stato.text += "->"+arrS[i]+"\n";
                              var tmps:String = arrS[i].toString();
                              if(tmps.substr(0,3) == "227")     {
                                   //label_stato.text += tmps+"\n";
                                   var IPport:String = tmps.substring( tmps.indexOf("("), tmps.indexOf(")") );
                                   var numeri:Array = IPport.split(",");
                                   var porta:Number = 0;     // numero di porta;
                                   var LSB:Number = numeri[numeri.length-1];
                                   var MSB:Number = numeri[numeri.length-2];
 
                                   label_stato.text += "Connessione passiva\n" + MSB+ " " + LSB+"\n";
                                   porta = (MSB *256) + LSB;
                                   s_dati.connect("ftp.******.it", porta);
                                   s.writeUTFBytes("RETR index.php\n");
                              }
                         }
                    }
                    
                    function erroreIO(evt:IOErrorEvent):void     {
                         label_stato.text += "\nERRORE " + evt.text;
                    }
                    
                    // crea la socket
                    s = new Socket();
                    s_dati = new Socket();
                    
                    // gestione eventi
                    s.addEventListener(Event.CONNECT, connesso);
                    s.addEventListener(ProgressEvent.SOCKET_DATA, progresso);
                    s.addEventListener(IOErrorEvent.IO_ERROR, erroreIO);
                    s.addEventListener(SecurityErrorEvent.SECURITY_ERROR, erroreSicurezza);
                    s.addEventListener(Event.CLOSE, chudi);
                    s_dati.addEventListener(Event.CONNECT, connessoDati);
                    s_dati.addEventListener(ProgressEvent.SOCKET_DATA, riceviDati);
                    s_dati.addEventListener(IOErrorEvent.IO_ERROR, erroreIO);
                    s_dati.addEventListener(SecurityErrorEvent.SECURITY_ERROR, erroreSicurezza);
                    s_dati.addEventListener(Event.CLOSE, chudi);
                    s.connect("ftp.****.it", 21);
               }
 
 
               protected function btn_dati_clickHandler(event:MouseEvent):void
               {
                    label_stato.text += tx_comandi.text+"\n";
                    s.writeUTFBytes(tx_comandi+"\n");
               }
 
Replies
  • Currently Being Moderated
    Mar 18, 2010 9:13 AM   in reply to Marco_01_88

    Hello Marco

    as you too are designing FTP client if you could help me on this

    We are using  flash.net.socket  to make a FTP client; everything is working fine except its not reading file names with special characters like underscore hypen
    for example it reads abc.jpg but skips ab_c.jpg
    any help

     

    Prashant

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2011 6:21 PM   in reply to Marco_01_88

    Hi,

    I'm having the same problem, I fight with this for last week and nothing, I cant find a working example of socket connection on the internet, local work ok, but on server i get one of all of this errors all time:

    SecurityError–>Error #2048,

    *** Security Sandbox Violation ***,

    Warning: [strict] Ignoring policy file at xmlsocket://xxxxxxx.com:21 due to incorrect syntax.  See http://www.adobe.com/go/strict_policy_files to fix this problem.

    I read and try all adobe answers for the problem: Security.loadPolicyFile; crossdomain.xml...

    Updates, others webrowsers...

    I check all webpages about this problem and nothing.

    Follow some lines I try for last week:

     

    Security.loadPolicyFile("http://www.xxxxx.com:80");    or
    Security.loadPolicyFile("http://www.xxxxx.com/crossdomain.xml");

    s = new Socket("xxxxx.com",21)

    s = new Socket("ftp.xxxxx.com",21)  <<< this one dont work even local

     

     

    It worked fine from my local machine. But when I deployed it on my server...

    Is this some kind of bug?

    Anyone know a working example that i can check?

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points