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");
}
2962 Views
3 Replies
Latest reply:
FYAO, Mar 26, 2011 6:21 PM




