PlayBook Simulator FTP Transfer Fails


Posted:   |  More posts about PlayBook simulator

This morning one of the forum posts was a question about problems using URLLoader to retrieve a file over FTP.

My first response was to suggest that the poster may be mistakenly thinking he could use the HTTP protocol to get to something over FTP. There was nothing in the URLLoader docs to suggest it handles FTP, and as usual with my ActionScript3 queries I found almost nothing on the web with a search or two, other than one post where people said you can't do it.

It turns out I was quite wrong and, as with the Python urllib tools, URLLoader transparently handles FTP under the covers. You can even include a userid and password in the URL, as with Python's approach. (It works, but I still find no docs or search results saying that.)

Unfortunately, with the current simulator (Beta 2, v0.9.2) it doesn't actually work. I analyzed with tcpdump on my router and was able to see the full FTP session, with login, switch to passive mode, checking size of file, and retrieval of data. For my test case, it was a local FTP site with authentication and an 82 byte text file, but I also tried with an external anonymous site and a larger file.

Basically the complete transfer succeeds, with all data received, yet before sending Event.COMPLETE the data seems to be simply discarded, with no indication why.

The original poster filed this as ticket TABLET-50. (Note that the link won't work for you unless you're logged into the BlackBerry issue tracker, and they make the ticket public. In the past all tickets were visible but I guess as they get closer to release they've decided it's time to make tickets private by default, so they can vet them for security risks and such.)

Here's the code for a simple test:

package
{
    import flash.display.Sprite;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.events.*;
    import flash.utils.*;
    import flash.net.*;
    import mx.utils.ObjectUtil;

    import qnx.ui.text.Label;

    [SWF(width="1024", height="600", backgroundColor="#5588ff", frameRate="20")]
    public class FtpTest extends Sprite
    {
        private var logo:Label;
        private var loader:URLLoader;

        public function FtpTest()
        {
            var logoFormat:TextFormat = new TextFormat();
            logoFormat = new TextFormat();
            logoFormat.size = 22;

            logo = new Label();
            logo.format = logoFormat;
            logo.text = "FTP Test";
            logo.autoSize = TextFieldAutoSize.LEFT;
            logo.x = logo.y = 10;

            addChild(logo);

            var request:URLRequest = new URLRequest("ftp://ftp2.bom.gov.au/anon/gen/fwo/IDA00001.dat");
            // next one shows how to do authenticated login, the above is anonymous
            // var request:URLRequest = new URLRequest("ftp://user:password@example.com/path/myfile.text");
            request.method = URLRequestMethod.GET;

            loader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, onEvent);
            loader.addEventListener(IOErrorEvent.IO_ERROR, onEvent);
            loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onEvent);
            loader.load(request);
            }

        private function onEvent(e:Event):void
        {
            trace(e.type, e);
            if (e.type == Event.COMPLETE) {
                trace("data", ObjectUtil.toString(loader.data));
                logo.text = "Got " + String(loader.bytesLoaded) + " bytes" +
                    "\nData: " + ObjectUtil.toString(loader.data);
            }
        }
    }
}
Comments powered by Disqus