Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:49:50+00:00 2026-06-10T08:49:50+00:00

I have an AS3 Script which connects to an FTP server and retrievs file/folder

  • 0

I have an AS3 Script which connects to an FTP server and retrievs file/folder list.
The script works fine when the device is connected to internet via WIFI or LAN but it fails to login when it’s connected via mobiles 3G

Here’s my code :

import flash.events.ProgressEvent;
import flash.events.Event;
import flash.net.Socket;
import flash.events.IOErrorEvent;
import flash.errors.IOError;
//
var ftp_host:String="ftp.server.com";
var ftp_port:Number=21//or your ftp port;
var ftp_username:String="username";
var ftp_password:String="password";
var ftp_path:String="/";
var s,r;
var listOfFiles:Array;
//


readFromFTP()

function readFromFTP(e=null){
    s = new Socket(ftp_host,ftp_port);
    r = new Socket();
    listOfFiles=new Array();
    s.addEventListener(IOErrorEvent.IO_ERROR,onIOERR);
    s.addEventListener(ProgressEvent.SOCKET_DATA, onReturnData);
    s.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecERR);
    r.addEventListener(ProgressEvent.SOCKET_DATA, onServData);
    r.addEventListener(Event.CONNECT, onPasvConn);
    r.addEventListener(IOErrorEvent.IO_ERROR,onIOERR);
    r.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSecERR);

    loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, handleGlobalErrors);
}


function onReturnData(evt:ProgressEvent)
{
    var d = s.readUTFBytes(s.bytesAvailable);
    trace(d);
    text_txt.appendText(d);
    if(d.indexOf("220 ")>-1){
       text_txt.appendText("Username sent\n");
       s.writeUTFBytes("USER "+ftp_username+"\n");
       s.flush()
    }
    if(d.indexOf("331 ")>-1){
        text_txt.appendText("Password sent\n");
       s.writeUTFBytes("PASS "+ftp_password+"\n");
       s.flush()
    }
    if (d.indexOf("230") > -1)
    {
        text_txt.appendText("PASV command sent\n");
        s.writeUTFBytes("PASV \n");
        s.flush();
    }
    var a = d.indexOf('227');
    if (a > -1)
    {
        var st = d.indexOf("(",a);
        var en = d.indexOf(")",a);
        var str;
        str = d.substring(st + 1,en);
        var a2 = str.split(",");
        var p1 = a2.pop();
        var p2 = a2.pop();
        var ip:String = a2.join(".");
        var port:int=(p2*256)+(p1*1);      
        r.connect(ip, port);
    }
    if(d.indexOf("226 ")>-1){
        text_txt.appendText("QUIT command sent\n");
        s.writeUTFBytes("QUIT \n");
        s.flush();
    }
    if(d.indexOf("221 ")>-1){
    }
}
function onPasvConn(evt:Event):void
{
    //trace("CONNECTED TO DATA PORT");
    text_txt.appendText("CONNECTED TO DATA PORT\n");
    s.writeUTFBytes("NLST "+ftp_path+"\n");
    s.flush();
}
function onServData(evt:ProgressEvent):void
{
    var d = r.readUTFBytes(r.bytesAvailable);
    trace(d);
    text_txt.appendText(d);
}
function onIOERR(evt:IOErrorEvent)
{
    trace(evt.errorID+":"+evt.text);
    text_txt.appendText(evt.errorID+":"+evt.text);
}

function onSecERR(evt){
    text_txt.appendText("Security error\n");
}

function handleGlobalErrors(evt){
    text_txt.appendText("Unhandeled Error\n");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:49:51+00:00Added an answer on June 10, 2026 at 8:49 am

    Finaly I fixed the bug.

    For some reason the server didn’t respond to command with (\n) linebreaks.

    I changed it to (\r\n) and it’s working fine now

    I hope this helps someone

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working mic recording script in AS3 which I have been able
I'm having trouble with a XMLSocket script in AS3. I have a java server
I have managed to create an AS3 script that uses file.download(urlRequest); - this is
I have a AS3 swf [1] that is loading another AS2 swf [2] which
Hey all, basically i have an empty AS3 fla file with just the following
i don't have intellisense when writing AS3 script in flash cs4, and it's only
I have an ant script to compile and generate an AIR file, and it
I have exported data .xls file using as3. var xml:ArrayCollection; xml=Labneuron8.lastResult.Response.Terminal as ArrayCollection; var
I am wondering if I can call a PHP script from AS3 and have
I have a folder /assets/animations filled with .swf files. I would like my AS3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.