Stuff I am building:


Ted Patrick - Events & Community @ Adobe Systems


Note: This is the personal blog of Ted Patrick. The opinions and statements voiced here are my own.



FlexFTP - FTP Client in Flex using flash.net.Socket

DIGG IT!     24 Comments Published Friday, May 11, 2007 at 8:43 AM .

Binary Sockets are so cool, you can connect to any type of TCP/IP server, yes any even FTP! I could not find the developers name (got it! Mali!!!) but Maliboo.pl has posted source for an FTP client in Apollo and client classes in AS3.

Project Source

flash.net.Socket


Great Work Mali!

Ted :)

24 Responses to “FlexFTP - FTP Client in Flex using flash.net.Socket”

  1. # Blogger maliboo

    "mali" is shortcut from maliboo: my nickname ;)
    My full name is Maciej Maliborski.  

  2. # Blogger Ted Patrick

    Maciej great work! Ted :)  

  3. # Blogger maliboo

    Thanks ;)

    But the main problem with FTP component/library/whatever ;) is SERIOUSY lack of functionality in Socket class. You can't get status/amount of flushing (sending data) process:
    http://tech.groups.yahoo.com/group/flexcoders/message/72018

    It major PITA.  

  4. # Blogger Ted Patrick

    Maliboo,

    flash.net.Socket is intentionally simple. It is very low level metal there directly against the TCP/IP layers within Flash Player.

    The key is realizing that you can and "should" build higher level APIs around it to be productive. This was done in Flex Data Services to neutralize the transport layers.

    I was thinking that it was ripe for a model like Twisted where you can defer execution until packets/blocks are complete. Right now you have to handle all the data exchange and byte-blockery yourself which is labor-intensive.

    There is also a desire to program on a Syncronous manner. This became very clear when Darron had issues with FlashVNC.

    A higher level socket library is needed. :)

    My 2 cents,

    Ted :)  

  5. # Anonymous darron

    As Ted said, I had some major problems with FVNC initially. Programming sockets in a synchronous manner is a much easier mental model, and I was banging my head against a wall trying to figure out the best way to deal with the asynchronous nature of the flash.net.Socket class.

    FVNC now has a solution in place that takes advantage of the asynchronicity nature of the Socket class. It's a little harder to wrap your head around than a simple readyByte(); readInt(); style of coding, but in the end it turned out extremely well, and I'm happy with the current solution.

    Take a look at RFBParser from http://svn1.cvsdude.com/osflash/fvnc/trunk/fvnc/src/fvnc/rfb/ and drill down from there. Basically, we build a parse tree as data becomes available, and when we have enough data to complete a message, we process it. Works great!  

  6. # Blogger maliboo

    I understand that. But knowing output buffer status is (for me) crucial (and low level ;)) like knowing input buffer with Socket::bytesAvailable. There's no such property like outputBytesAvailable. Any kind of really simple info:
    - outputBytesAvailable:int (is output buffer clear and ready to fill again)
    - flush():Boolean (when flushing empty output buffer returns false)
    - flush():Throw Error (when flushing empty buffer)
    - flush() are ALWAYS synchronous when sending less than 1024b (or even 8bytes ;))

    Any simple (true/false value) thing would be VERY helpful. Especially with very large files sending. And I can bet, that this would be very painful with incoming Apollo apps for interchanging binary data over binary Sockets with simple back-end.

    Comparing this to input: it's like getting progress event only when whole data is available (like in XMLSocket)

    @Darron:
    Incoming data with ProgressEvent aren't problem here. Main problem is lack of info about outgoing data.
    In FTP server context: when you start uploading process, you can fill+flush buffer in intervals, but you don't get ANY info about progress from server, until FTP doesn't return you some message that the uploading process is ended.

    You fill buffer in datachunks, flush it, close socket in AS via Socket::close(), but physically this socket isnt't closed- data are still sending from your computer to FTP. It seems that REALLY socket closing is deferred until it's realu flushed, on really, really low player level.

    Try to play with pl.maliboo.ftp.invokers::UploadInv with some "large" (100kB+) files. In VNC you've probably send small amount of data form client to VNC server, so it's progress may be neglected. In FTP when sending file I can only show undetermined progress bar :(

    Of course, there are some workarounds, but only workarounds:(  

  7. # Blogger ?ukasz

    Im developing http://asql.mooska.pl
    and Ive got the same problem. When trying to insert something bigger, i.e. into blob field (image, whatever) only response I get is after whole process. No way I can get any progress event, while uploading, wich is quite annoying.

    Need some enhanced Socket class :)  

  8. # Anonymous Justin Levi Winter

    Here are a couple of threads on apollocoders with a similar focus. I would love to see an advanced library for socket class.

    Seems there was a lot of talk about ftp clients when flex 2.0 was first coming out, but there hasn't been much released since.

    http://tech.groups.yahoo.com/group/apollocoders/message/507

    http://tech.groups.yahoo.com/group/apollocoders/message/623  

  9. # Blogger James

    Hi, this is an impressive tool. However, Its just a proof of ability. If the tool could be a website component to allow the upload of files via ftp, integrated into a web page. Now that would be something.
    However, I would imagine you would have done this, and that its probably not possible due to Web page sand boxing.

    If it is, I think it would be a very well received app. I would love it for some stuff I am working on.

    Could any knowledgeable Flex/AS3 developer shed some light about this possibility please.

    James  

  10. # Anonymous Anonymous

    Is there a way to upload a file using this technique from web browser? I'm searching a method to upload very large files (2-3 GB) with progress bar using only web browser.  

  11. # Blogger kiran

    Hey am using Flex 3...I'm not able to open this project...the error message i get is
    "This application cannot be run.(Error: this application requires a version of the Adobe Intergrated Runtime(AIR) which is no longer supported.Please contact the application author for updated version.)"

    Please help...Thanx in advance....  

  12. # Anonymous Anonymous

    Did anyone get this working for Flex 3? if so please let me know, mr5080@comcast.net
    thanks!  

  13. # Anonymous Anonymous

    line #57 of FTPFile.as is wrong

    line reads : var name:String = fields[8];

    should be :

    var name:String="";for( var i:int = 8; i < fields.length; i++ ) name+= (fields[i]+((i!=fields.length-1)?" ":""));  

  14. # Blogger Dustin

    hello there.
    I am trying to get this code working but keep getting an IO Error when the app is redirected the passive port.
    I haven't yet been able to debug why its getting the IO Error, and am wondering if anyone else saw this same behavior?

    thanks!
    Dustin  

  15. # Blogger vikram bhatla

    when library try to open passive mode connection using another socket its throwing error-:Data connection already open.
    I am unable to correct it. can anybody suggest me what's wrong  

  16. # Anonymous Anonymous

    I havent looked at any of the code, but I know when using sockets in flash there is documentaiton that talks about denying use of ports below 1027.

    FTP is by default port 21...right? Could this be whats giving many people problems  

  17. # Blogger Konttori

    works just fine in flex 3 after some minor changes. At least in air apps.  

  18. # Anonymous lexa - ActionScript Flash and Flex developper

    hi

    I am a Fench ActionScript developer working as a freelance. This month I used the FlexFTP classes to deliver an AIR ftp client to the TF1 group.

    I had to correct some bugs and add features such as a system to progress determine the upload progression during upload.

    I have 2 questions :
    - do the Apache License, Version 2 force my client to publish the modifyed source code (which would be good I think)
    - where should i publish the code if i am allowed to do so?

    thank you,
    lex.
    http://silex-ria.org/lex  

  19. # OpenID jejad

    anyone guide me whats the step by step procedure should be done in order to run this on flex3.please...help..email me.jejad2000@yahoo.com.tanx

    i'd tried this procedure

    I put the library files in the root of the project and added
    xmlns:ftp="pl.maliboo.ftp.core.*" to tag

    import pl.maliboo.ftp.events.FTPEvent;
    import mx.controls.treeClasses.TreeItemRenderer;
    import mx.core.IDataRenderer;
    import flash.filesystem.File;
    import pl.maliboo.ftp.Commands;
    import pl.maliboo.ftp.FTPCommand;
    import pl.maliboo.ftp.FTPFile;
    import pl.maliboo.ftp.events.FTPEvent;
    import pl.maliboo.ftp.core.FTPClient;
    import pl.maliboo.ftp.utils.ConsoleListener;
    private var list:ConsoleListener;

    public function makeConnection (host:String, port:Number):void
    {
    if (list == null)
    list = new ConsoleListener(client, output);
    client.addEventListener(FTPEvent.CONNECTED, handleConnected);
    client.connect(host, port);
    }

    public function handleConnected (evt:FTPEvent):void
    {
    client.addEventListener(FTPEvent.LOGGED, handleLogged);
    client.login(username.text, passwd.text);
    }


    i've got this error after compiling "Type was not found or was not a compile-time constant: FTPEvent."  

  20. # Anonymous Anonymous

    Hi, while i was doing the debug into flex i noticed that into the debug console a sort of upload's progress status is logged. Anyone know how to use this log? The code that logs the progress is into pl.maliboo.ftp.invokers.UploadInv.as @ line 154. I've tried to dispatch some event but they weren't dispatched properly. I've also tried to read that properties but i didn't find an Event dispatched while the upload action.
    thank you for the attention!  

  21. # Anonymous Anonymous

    Hi, Great app! I am also trying to modify this to run in Flex. I have got as far as removing all references to the flash.filesystem package. This leaves me with a great looking ftp directory browser! I really need some pointers for replacing the filesystem references in the upload and download invokers. So I can get the app to do something useful. If anyone could point me in the right direction I would really appreciate it. Cheers.  

  22. # Anonymous Rob

    mali hit on something i've come across as well. The socket close command either issued on the client side and if your in passive mode and receiving data from ftp server and it sends a 226 back and data is still coming into socket .. well if you listen on the socket port on when the close happens, sometimes it does sometimes it does not. I believe the ftp server is in fact sending the close command however flex does not "always" close the socket. My testing is with small ascii files as well. I think I have other program execution going on as well as the ftp is ascyncronous and flex gets confused and does not close the socket.

    I basically put in a listener and when the socket is closed on the data transfer port i want to execute additional code to close the port 21 port connection, this works "most" of the time but 2 out of 10 times it never closes the socket.
    I'm thinking this is a bug here. I've not gone as far as running a sniffer to see what the communication is between the client and server, but I might go there next.  

  23. # Anonymous Rob

    I have built a perfectly working ftp client in my application. However the sandbox security issue although i trap the error seems to be messing with my ftp server. I login and get a file and get the 226.. i wait for the Event.Close on the data transmission port and do other things, after about 10 seconds i get the message on 2048 and flex cant load data from the data transfer port. I thought i don't give a rip on the error and trapped it, but after this runs for 2 days it ftp's the server every 5 minutes during daylight hours then the ftp server begins to blow out. I check the netstat and the connections are being closed. so i'm thinking this error is somehow doing something. I have a program i wrote in visual basic 6 some time back and it ftp's this same server every 2 minutes and the ftp server NEVER messes up (vb app running and not the flex 3 app). vb ftp is via a ms control.. very easy to use. (hint hint adobe) I can't believe this hassle. I trying to do a very simple operation like this. FTP obviously cannot have any cross domain policies as it's not realistic as the ftp server could/should be anywhere and under someone else control.

    BOOO!!  

  24. # Anonymous Rob

    Well after playing with a network sniffer i was able to figure out the socket issues using ftp commands. It appears that the sandbox errors have no bearing on the connection or socket communication. I'm not really sure what the errors are doing... I'm only getting files from an ftp server, not putting files.

    Rob  

Post a Comment

Where to find me:

Ted on Twitter - @AdobeTed
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe


Latest

Lists

Links

Jobs

Flex Jobs
city, state, zip

Archives