I'm using the Socket class to upload a JPG via FTP. I can make the connection and send the file, but for some reason the when I open the uploaded file, the images looks corrupted. I looks like some of the pixel groups are just put in the wrong place like a puzzle. And some areas have a slight color tint. I'm assuming my socket.writeBytes() method is just not writing in sequence. Does anyone have a solution? I have sample code of my timerevent that writes out 4096 bytes of data at a time. Since there are no built-in events dispatched when the writeBytes is complete…has anyone come across a solution for detecting when the send is done? I've tried fashion a small FTP client similar to http://maliboo.pl/projects/FlexFTP/ but it seems like files larger than 32K seem to be written incorrectly. Here's the timer event that runs every 500 miliseconds to writeBytes:

PHP Code:
//_dataBuffer = 4096;
//_bytes = ByteArray to upload;
//_dataTotal = _bytes.length;
//_dataOffset = 0;

function dataTimerTick(e:TimerEvent):void {
trace("TICK"_timer.currentCount_dataOffset_bytes.length,
_dataBuffer);
if ((
_dataTotal)<=0) {
//Complete
_timer.stop();
this.dispatchEvent(new Event(FTPEvent.UPLOADtrue));
return;
}
_dataSocket.writeBytes(_bytes_dataOffset,_dataBuffer);
_dataSocket.flush();
_dataOffset+=_dataBuffer;
_dataTotal-=_dataBuffer;
if (
_dataTotal<=_dataBuffer) {
_dataBuffer=_dataTotal;
}