3 Replies Latest reply on Apr 2, 2009 2:59 PM by Jeff Swartz

    Using Socket class

    released87 Level 1
      Hi,

      I am new to sockets and I am unsure whether I can use the socket class to accomplish a specific task. Basically I need to create an FTP installer for a Website. I basically need to copy local files to a directory on a remote server without using PHP, at least until I can transfer a PHP file.

      I am creating a Website installer, so a customer can download the .AIR file to their computer, enter their domain name, username and password and connect to the host. From there I need to just upload a PHP page that will contain the script I need to use HTTPService from AIR to transfer the rest of the files. However, I do not want the customer to have to upload the PHP file first before running the Installer.

      So my question is it possible to 1) Connect to a remote host with username/password/port/domain 2) Upload 1 file, with the Flash Socket class? Am I on the right path?

      Jesse
        • 1. Re: Using Socket class
          Jeff Swartz Level 3
          Yes, you can connect to an FTP server using the Socket class:

          var socket:Socket = new Socket("localhost", 21);
          socket.addEventListener(ProgressEvent.SOCKET_DATA, socketProgress);

          I was able to use the ActionScript code posted on this blog to *connect* to an FTP server:

          http://actionscript3.blogs2k.com/2008/08/05/ActionScript%203%20-%20simple-uploading-via-so cket-ftp%20-AS3

          However, my FTP server complained when I tried to establish a passive (PASV) FTP connection ("Can't open passive connection: Address family not supported by protocol family.") I am not familiar enough with FTP commands to figure out how to upload data.
          • 2. Re: Using Socket class
            released87 Level 1
            thanks this definately helps, I was able to do everything except upload the file, but I probably just need to mess with it a little more...

            I wish I knew more about FTP myself so I could help you connect with a passive connection. My only suggestion is to check FTP log in Dreamweaver, which will show you everything that happens in FTP talk. Try to enable passive mode in Dreamweaver or your FTP client and see if it works, then at least you know if you can...
            • 3. Re: Using Socket class
              Jeff Swartz Level 3
              You should look at the FlexFTP FTP client mentioned on Ted Patrick's blog:

              http://www.onflex.org/ted/2007/05/flexftp-ftp-client-in-flex-using.php

              The source code is written for an old beta version of AIR, but it may work with some fiddling.(Among other things, change "ApolloApplication" to "WindowedApplication" in the main MXML file, and remove "import mx.rpc.soap.errors.ClientInputError;" from the pl.maliboo.ftp.invokers.LoginInv class.)

              BTW, I think that to successfully upload files with FTP, you need to set the FTP server to "passive" mode (using the FTP "PASV" command).