MDM Zinc – FTP Manager

Hello.
This is a class I've done long time ago. I'm quite sure it will be helpfull to some people (at least one, the one who sent me an email asking for this class ;) ).

First the class:

Actionscript:
  1. /*
  2. * Class written by Xavier MARTIN (xxlm or zeflasher)
  3. * http://dev.webbymx.net
  4. * http://www.webbymx.net
  5. * If you are using this class, I will be glad to receive a postcard of your place :)
  6. * To do so please visit http://dev.webbymx.net and go in the about page do get my details...
  7. */
  8.     import mdm.*;
  9. //  for the delegate class inside
  10.     import com.bourre.commands.*;
  11. //  log event
  12.     import com.bourre.log.*;
  13.     import com.bourre.utils.LuminicTracer;
  14.  
  15.     import net.webbymx.zinc.DateManager;
  16.     import net.webbymx.zinc.FileSystemManager;
  17.  
  18. dynamic class net.webbymx.zinc.FTPManager {
  19. /******************************************************************************
  20. * PRIVATE VARIABLES
  21. ******************************************************************************/
  22. //  EventDisptacher
  23.     private var dispatchEvent:Function;
  24.     public var addEventListener:Function;
  25.     public var removeEventListener:Function;
  26.  
  27. //  ftp log
  28.     private var _ftp_server:String;
  29.     private var _ftp_port:String;
  30.     private var _ftp_username:String;
  31.     private var _ftp_password:String;
  32.     private var _ftp_folder:String;
  33.  
  34. //  MDM ftp connection
  35.     private var _ftp:mdm.FTP;
  36.  
  37. //  ftp management
  38.     private var _ftp_connected:Boolean;
  39.     private var _ftp_siInterval:Number;
  40.     private var _ftp_row:Number;
  41.     private var _ftp_file:Number;
  42.  
  43. //  ftp informations
  44.     private var _ftp_localFiles:Array;
  45.     private var _ftp_remoteFiles:Array;
  46.     private var _ftp_localFile:String;
  47.     private var _ftp_remoteFile:String;
  48.     private var _ftp_totalBytes:Number;
  49.     private var _ftp_currentBytes:Number;
  50.     private var _ftp_lastCachedBytes:Number;
  51.     private var _ftp_fileTansfered:Boolean;
  52.     private var _ftp_localRoot:String;
  53.     private var _ftp_start:Boolean;
  54.     private var _ftp_root:String;
  55.     private var _ftp_actualdir:String;
  56.  
  57.  
  58.  
  59. //  Dispatched
  60.     public var aborted:Function;
  61.     public var busy:Function;
  62.     public var connected:Function;
  63.     public var dirChanged:Function;
  64.     public var dirCreated:Function;
  65.     public var dirDeleted:Function;
  66.     public var error:Function;
  67.     public var fileDeleted:Function;
  68.     public var fileReceived:Function;
  69.     public var fileRenamed:Function;
  70.     public var fileSent:Function;
  71.     public var fileTransfered:Function;
  72.     public var indexFileReceived:Function;
  73.     public var listingDone:Function;
  74.     public var loggedIn:Function;
  75.     public var quit:Function;
  76.     public var ready:Function;
  77.     public var resolvedLinks:Function;
  78.  
  79.     public var scanLocalCompleted:Function;
  80.     public var scanRemoteCompleted:Function;
  81.     public var progress:Function;
  82.     public var write:Function;
  83.  
  84. /******************************************************************************
  85. * CONSTRUCTOR
  86. ******************************************************************************/
  87.     //  FTPManager(server:String, port:String, username:String, pwd:String [,localRoot:String, folder:String])
  88.     function FTPManager(server:String, port:String, username:String, pwd:String) {
  89.     //  dispatching event
  90.         mx.events.EventDispatcher.initialize(this);
  91.     //  FTP events (from zinc)
  92.         addEventListener("aborted", this);
  93.         addEventListener("busy", this);
  94.         addEventListener("connected", this);
  95.         addEventListener("dirChanged", this);
  96.         addEventListener("dirCreated", this);
  97.         addEventListener("dirDeleted", this);
  98.         addEventListener("error", this);
  99.         addEventListener("fileDeleted", this);
  100.         addEventListener("fileReceived", this);
  101.         addEventListener("fileRenamed", this);
  102.         addEventListener("fileSent", this);
  103.         addEventListener("fileTransfered", this);
  104.         addEventListener("indexFileReceived", this);
  105.         addEventListener("listingDone", this);
  106.         addEventListener("loggedIn", this);
  107.         addEventListener("quit", this);
  108.         addEventListener("ready", this);
  109.         addEventListener("resolvedLinks", this);
  110.  
  111.     //  FTP events added
  112.         addEventListener("scanLocalCompleted", this);
  113.         addEventListener("scanRemoteCompleted", this);
  114.         addEventListener("progress", this);
  115.         addEventListener("write", this);
  116.  
  117.     //  init variables
  118.         _ftp_server = server;
  119.         _ftp_port = port;
  120.         _ftp_username = username;
  121.         _ftp_password = pwd;
  122.  
  123.         _ftp_connected = false;
  124.         _ftp_localFiles = new Array();
  125.         _ftp_remoteFiles = new Array();
  126.         _ftp_localFile = null;
  127.         _ftp_remoteFile = null;
  128.  
  129.     //  preloader
  130.         _ftp_totalBytes = null;
  131.         _ftp_currentBytes = null;
  132.         _ftp_lastCachedBytes = null;
  133.         _ftp_fileTansfered = true;
  134.         _ftp_start = true;
  135.  
  136.  
  137.         if (arguments[4] != undefined && typeof(arguments[4]) == "string") {
  138.             _ftp_localRoot = arguments[4];
  139.             if(!mdm.FileSystem.folderExists(_ftp_localRoot)) mdm.FileSystem.makeFolder(_ftp_localRoot);
  140.         }
  141.         if (arguments[5] != undefined && typeof(arguments[5]) == "string") _ftp_folder = arguments[5];
  142.         else _ftp_folder = "none";
  143.     }
  144.  
  145. /******************************************************************************
  146. * PRIVATE FUNCTIONS
  147. ******************************************************************************/
  148.     private function getTransferProgress(Void):Void {
  149.     //  get bytes transfered
  150.         _ftp_currentBytes = _ftp.bytesTransfered;
  151.         if (_ftp_fileTansfered == false) {
  152.         //  if current bytes is not a Number
  153.             if (isNaN(_ftp_currentBytes)) return;
  154.             if (_ftp_currentBytes != _ftp_lastCachedBytes) {
  155.                 _ftp_lastCachedBytes = _ftp_currentBytes;
  156.                 dispatchEvent({type: "progress", target: this, bytesTransfered:_ftp_currentBytes, totalBytes:_ftp_totalBytes});
  157.             } else return;
  158.         } else {
  159.             _ftp_lastCachedBytes = null;
  160.             dispatchEvent({type: "progress", target: this, bytesTransfered:_ftp_currentBytes, totalBytes:_ftp_totalBytes});
  161.         }
  162.     }
  163.  
  164. //  dispatch the event write with the string passed in param
  165.     private function updateStatus(s:String):Void {
  166.         dispatchEvent({type: "write", target: this, txt:s});
  167.     }
  168.  
  169. //  OK
  170. //  Event Handler for the FTP
  171.     private function ftpEventHandler(event:Object) {
  172.         //updateStatus("\nid: "+event.id+" \nsevent: "+event.type);
  173.         //updateStatus("\nlast server reply: "+_ftp.lastReply);
  174.         var eventType:String = String(event.type).toUpperCase();
  175.  
  176.     // ABORTED EVENT
  177.         if (eventType == "ABORTED") {
  178.             dispatchEvent({type: "aborted", target: this});
  179.         //  nothing
  180.             return;
  181.         }
  182.  
  183.     // BUSY EVENT
  184.         if (eventType == "BUSY") {
  185.             dispatchEvent({type: "busy", target: this});
  186.         //  nothing
  187.             return;
  188.         }
  189.  
  190.     // FTP CONNECTED EVENT
  191.         if (eventType == "CONNECTED") {
  192.             dispatchEvent({type: "connected", target: this});
  193.         //  nothing
  194.             return;
  195.         }
  196.  
  197.     // FTP DIR CHANGED EVENT
  198.         if (eventType == "DIRCHANGED") {
  199.         //  show directory
  200.             updateStatus("\n\n************************************");
  201.             updateStatus("\nCurrent directory: "+_ftp.currentDir+"\n");
  202.             if (_ftp_start) {
  203.                 _ftp_start = false;
  204.                 _ftp_root = _ftp.currentDir;
  205.                 dispatchEvent({type: "loggedIn", target: this});
  206.             }
  207.             return;
  208.         }
  209.  
  210.     // FTP DIR CREATED EVENT
  211.         if (eventType == "DIRCREATED") {
  212.             dispatchEvent({type: "dirCreated", target: this});
  213.         //  show directory
  214.             return;
  215.         }
  216.  
  217.     // FTP ERROR EVENT
  218.         if (eventType == "ERROR") {
  219.             _ftp_fileTansfered = true;
  220.             clearInterval(_ftp_siInterval);
  221.             var lastError = _ftp.error;
  222.             dispatchEvent({type: "error", target: this});
  223.             updateStatus("\nError details: "+lastError);
  224.             return;
  225.         }
  226.  
  227.     // FTP FILE DELETED
  228.         if (eventType == "FILEDELETED") {
  229.             dispatchEvent({type: "fileDeleted", target: this});
  230.         //  show directory
  231.             return;
  232.         }
  233.  
  234.     // FTP FILE RECEIVED EVENT
  235.         if (eventType == "FILERECEIVED") {
  236.             clearInterval(_ftp_siInterval);
  237.             _ftp_fileTansfered = true;
  238.             getTransferProgress();
  239.             dispatchEvent({type: "fileReceived", target: this});
  240.         }
  241.  
  242.     // FTP FILE RENAMED EVENT
  243.         if (eventType == "FILERENAMED") {
  244.             clearInterval(_ftp_siInterval);
  245.             dispatchEvent({type: "fileRenamed", target: this});
  246.         }
  247.  
  248.     // FTP FILE SENT EVENT
  249.         if (eventType == "FILESENT") {
  250.             _ftp_fileTansfered = true;
  251.             clearInterval(_ftp_siInterval);
  252.             //getTransferProgress();
  253.             updateStatus("\nlocal file: "+_ftp_localFile);
  254.             updateStatus("\nremote file: "+_ftp_remoteFile);
  255.             updateStatus("\ntransfer time: "+_ftp.transferTime);
  256.  
  257.             updateStatus("\nDone");
  258.  
  259.  
  260.         //  going to the next file
  261.             _ftp_file++;
  262.         //  if there is no more file to upload for this directory
  263.             if (_ftp_file>= _ftp_localFiles[_ftp_row][1].length) {
  264.             //  going to the next one
  265.                 _ftp_row++;
  266.             //  reset file index
  267.                 _ftp_file = 0;
  268.             //  if there is still directory
  269.                 if (_ftp_row <_ftp_localFiles.length) {
  270.                     var dir:String = _ftp_localFiles[_ftp_row][0];
  271. mdm.Dialogs.prompt("row: "+_ftp_row+", "+_ftp_localFiles[_ftp_row]);
  272. mdm.Dialogs.prompt("dir: "+_ftp.currentDir+"/"+dir);
  273.                     if (!_ftp.dirExists(dir, mdm.SYNC)) _ftp.makeDir(dir, mdm.SYNC);
  274. var success = _ftp.success;
  275. mdm.Dialogs.prompt(success)
  276.                     _ftp.refresh(mdm.SYNC);
  277.                     _ftp.chDir(_ftp.currentDir+"/"+_ftp_localFiles[_ftp_row][0], mdm.SYNC);
  278. mdm.Dialogs.prompt("Current dir: "+_ftp.currentDir);
  279. var success = _ftp.success;
  280. mdm.Dialogs.prompt(success)
  281.                     uploadNextFile()
  282.                 } else {
  283.                     updateStatus("\n\nNo others files to upload");
  284.                 //  endUpdate();
  285.                 }
  286.             } else uploadNextFile();
  287.  
  288.  
  289.         //  check if there is still file to dldl for this dir
  290.             return;
  291.         }
  292.  
  293.     // FTP FILE TRANSFERED
  294.         if (eventType == "FILETRANSFERED") {
  295.             clearInterval(_ftp_siInterval);
  296.             dispatchEvent({type: "fileTransfered", target: this});
  297.         }
  298.  
  299.     // FTP INDEX FILE RECEIVED
  300.         if (eventType == "INDEXFILERECEIVED") {
  301.             clearInterval(_ftp_siInterval);
  302.             dispatchEvent({type: "indexFileReceived", target: this});
  303.         }
  304.  
  305.     // FTP LISTING DONE
  306.         if (eventType == "LISTINGDONE") {
  307.             clearInterval(_ftp_siInterval);
  308.             dispatchEvent({type: "listingDone", target: this});
  309.         }
  310.  
  311.     // FTP LOGGED EVENT
  312.         if (eventType == "LOGGEDIN") {
  313.             updateStatus("\nLogged in");
  314.  
  315.             if (_ftp_connected == false) {
  316.                 _ftp_connected = true;
  317.             //  switch directory if required
  318.                 if (_ftp != null && _ftp_folder != "none") {
  319.                     _ftp.chDir(_ftp_folder, mdm.SYNC);
  320.                 } else dispatchEvent({type: "loggedIn", target: this});
  321.             }
  322.             return;
  323.         }
  324.  
  325.     // FTP QUIT EVENT
  326.         if (eventType == "QUIT") {
  327.             dispatchEvent({type: "quit", target: this});
  328.         // nothing
  329.             return;
  330.         }
  331.  
  332.     // FTP READY EVENT
  333.         if (eventType == "READY") {
  334.             dispatchEvent({type: "ready", target: this});
  335.         // nothing
  336.             return;
  337.         }
  338.  
  339.     // FTP RESOLVED LINKS EVENT
  340.         if (eventType == "RESOLVEDLINKS") {
  341.             dispatchEvent({type: "resolvedLinks", target: this});
  342.         // nothing
  343.             return;
  344.         }
  345.     }
  346.  
  347.  
  348.     function uploadNextFile(Void):Void {
  349.     //  get the row [dir, [fileinfo, ...]]
  350.         var dir:String = _ftp_localFiles[_ftp_row][0];
  351. mdm.Dialogs.prompt("dir: "+dir+", file: "+dir+_ftp_localFiles[_ftp_row][0]+_ftp_localFiles[_ftp_row][1][_ftp_file][0])
  352.         var filesize:Number = mdm.FileSystem.getFileSize(dir+_ftp_localFiles[_ftp_row][0]+_ftp_localFiles[_ftp_row][1][_ftp_file][0]);
  353.         updateStatus("\n\nUploading new file");
  354.         updateStatus("\n  - filename: "+_ftp_localFiles[_ftp_row][1][_ftp_file][0]);
  355.         updateStatus("\n  - filesize: "+String(Math.round(filesize / 1024 * 100)/100)+" Kb ("+filesize+" Bytes)");
  356.     //  tweenFileTo = Math.round( (KbUplded+filesize) * 100 / KbToUpld);
  357.     //  tweening the file bar
  358.     //  mc_progressbar.mc_file.gotoAndStop(tweenFileTo);
  359.     //  loading the file
  360.         upload(_ftp.currentDir+dir+_ftp_localFiles[_ftp_row][1][_ftp_file][0], dir, _ftp_localFiles[_ftp_row][1][_ftp_file][0], filesize);
  361.     }
  362.  
  363.  
  364. /******************************************************************************
  365. * PUBLIC FUNCTIONS
  366. ******************************************************************************/
  367.     function scanFolder(scanTo:String, returnArray:Array):Void {
  368.         var rootPath:String;
  369.         var dispatch:Boolean = true;
  370.  
  371.     //  adding the "/" at the end of the string if not here
  372.         if (scanTo.charAt(scanTo.length-1) != "/") scanTo += "/";
  373.         rootPath = scanTo;
  374.  
  375.     //  changing the directory of the ftp
  376.         _ftp.chDir(scanTo, mdm.SYNC);
  377.  
  378.         switch (arguments.length) {
  379.             case 5:
  380.             //  if we are in a recursive call
  381.                 if (arguments[4] != undefined && typeof(arguments[4]) == 'boolean') dispatch = arguments[4];
  382.             case 4:
  383.             //  if we have scan exception or if we are in a recursive call
  384.                 if (arguments[3] != undefined && typeof(arguments[3]) == 'object' && arguments[3].length> 0) var exception:Array = arguments[3];
  385.                 else if (arguments[3] != undefined && typeof(arguments[3]) == 'boolean') dispatch = arguments[3];
  386.             case 3:
  387.             //  path to the root
  388.                 if (arguments[2] != undefined && typeof(arguments[2]) == 'string') rootPath = arguments[2];
  389.                 break;
  390.         }
  391.  
  392.     //  get all the file of the folder
  393.         var tmpFiles:Array = _ftp.getFileList();
  394.         for (var i:Number = 0; i<tmpFiles.length; i++) {
  395.             tmpFiles[i][1] = DateManager.ftpDate(tmpFiles[i][1]);
  396.         }
  397.  
  398.         if (tmpFiles.length> 0) returnArray.push([rootPath, tmpFiles]);
  399.  
  400.     //  get all the folder of the folder
  401.         var tmpFolder:Array = _ftp.getFolderList();
  402.         var allFolder:Array = new Array();
  403.         for (var i:Number = 0; i<tmpFolder.length; i++) {
  404.             if(tmpFolder[i][0] != "" && tmpFolder[i][0] != "." && tmpFolder[i][0] != "..") allFolder.push(tmpFolder[i][0]);
  405.         }
  406.  
  407.         for (var fld:Number = 0; fld<allFolder.length; fld++) {
  408.             if (exception != undefined) {
  409.                 var found:Boolean = false;
  410.                 for (var i:Number = 0; i<exception.length; i++) {
  411.                     if (allFolder[fld]+"/" == exception[i]) found = true;
  412.                 }
  413.                 if (!found) scanFolder(scanTo+allFolder[fld]+"/", returnArray, rootPath+allFolder[fld]+"/", exception, false);
  414.             } else scanFolder(scanTo+allFolder[fld]+"/", returnArray, rootPath+allFolder[fld]+"/", false);
  415.         }
  416.         if (dispatch) {
  417.             _ftp.chDir(scanTo, mdm.SYNC);
  418.             dispatchEvent({type: "scanRemoteCompleted", target: this});
  419.         }
  420.     }
  421.  
  422.     public function scanRemoteFolder() {
  423.         scanFolder(_ftp.currentDir, _ftp_remoteFiles, "/");
  424.     }
  425.  
  426.     public function scanLocalFolder() {
  427.         var fs:FileSystemManager = new FileSystemManager();
  428.         fs._owner = this;
  429.         fs.onScanCompleted = function () {
  430.             this._owner.dispatchEvent({type: "scanLocalCompleted", target: this._owner});
  431.         }
  432.         if (arguments[0] != undefined){
  433.             var tmpArray:Array = new Array();
  434.             if (typeof(arguments[0]) == 'string' ) tmpArray.push(arguments[0]);
  435.             if (typeof(arguments[0]) == 'object' ) tmpArray = arguments[0];
  436.             fs.scanFolder(_ftp_localRoot, _ftp_localFiles, "/", tmpArray);
  437.         } else fs.scanFolder(_ftp_localRoot, _ftp_localFiles, "/");
  438.     }
  439.  
  440. //  connection to the FTP
  441.     public function connect() {
  442.         updateStatus("\n\nConnecting to FTP...");
  443.         if (_ftp == null) {
  444.             _ftp = new mdm.FTP(_ftp_server, _ftp_port);
  445.             _ftp._owner = this;
  446.         //  FTP properties
  447.             _ftp.transferMode = "binary";
  448.             _ftp.async = false;
  449.  
  450.         //  EVENTS REFERENCES
  451.             _ftp.onAborted = Delegate.create(this, ftpEventHandler);
  452.             _ftp.onBusy = Delegate.create(this, ftpEventHandler);
  453.             _ftp.onConnected = Delegate.create(this, ftpEventHandler);
  454.             _ftp.onDirChanged = Delegate.create(this, ftpEventHandler);
  455.             _ftp.onDirCreated = Delegate.create(this, ftpEventHandler);
  456.             _ftp.onError = Delegate.create(this, ftpEventHandler);
  457.             _ftp.onFileDeleted = Delegate.create(this, ftpEventHandler);
  458.             _ftp.onFileReceived = Delegate.create(this, ftpEventHandler);
  459.             _ftp.onFileRenamed = Delegate.create(this, ftpEventHandler);
  460.             _ftp.onFileSent = Delegate.create(this, ftpEventHandler);
  461.             _ftp.onTransfered = Delegate.create(this, ftpEventHandler);
  462.             _ftp.onIndexFileReceived = Delegate.create(this, ftpEventHandler);
  463.             _ftp.onListingDone = Delegate.create(this, ftpEventHandler);
  464.             _ftp.onLoggedIn = Delegate.create(this, ftpEventHandler);
  465.             _ftp.onQuit = Delegate.create(this, ftpEventHandler);
  466.             _ftp.onReady = Delegate.create(this, ftpEventHandler);
  467.             _ftp.onResolvedLinks = Delegate.create(this, ftpEventHandler);
  468.  
  469.         //  actual login
  470.             _ftp.login(_ftp_username,_ftp_password);
  471.         }
  472.     }
  473.  
  474.  
  475. //  changing directory to the one specified (full path)
  476.     public function getPath(s:String):Array {
  477.         var pathArray:Array = new Array();
  478.         pathArray = s.split("/");
  479.  
  480.         var tmpName:Array = new Array();
  481.         tmpName = pathArray[pathArray.length-1];
  482.  
  483.         pathArray.splice(pathArray.length-1);
  484.         var tmpDir:String = pathArray.join("/");
  485.  
  486.         var finalArray:Array = new Array(tmpName, tmpDir);
  487.         return (finalArray);
  488.     }
  489.  
  490. //  downloading a file
  491.     //  arguments[2] -> filesize
  492.     public function download(r:String, l:String):Void {
  493.  
  494.         var infos:Array = new Array();
  495.         infos = getPath(r);
  496.  
  497.         var linfos:Array = new Array();
  498.         linfos = getPath(l);
  499.  
  500.     //  if the directory is not the same, changing it
  501.         if (_ftp.currentDir != infos[1]) _ftp.chDir(infos[1]);
  502.  
  503.     //  creating the folder if it not existing
  504.         if (!mdm.FileSystem.folderExists(linfos[1])) mdm.FileSystem.makeFolder(linfos[1]);
  505.  
  506.         updateStatus("\ndownloading "+infos[0]);
  507.         if (r != undefined) {
  508.             _ftp_localFile = l;
  509.             _ftp_remoteFile = infos[0];
  510.             _ftp_totalBytes = _ftp.getFileSize(_ftp_remoteFile);
  511.             if (isNaN(_ftp_totalBytes)) {
  512.                 _ftp_totalBytes == null;
  513.                 updateStatus("\nCannot get remote file size");
  514.                 return;
  515.             }
  516.             updateStatus("\nRemote file size: "+_ftp_totalBytes);
  517.             _ftp_fileTansfered = false;
  518.             if (_ftp != null) {
  519.                 _ftp_siInterval = setInterval(this, "getTransferProgress", 500);
  520.                 //  creating the folder in the ftp folder
  521.                 _ftp.getFile(_ftp_remoteFile, _ftp_localFile, mdm.ASYNC);
  522.             }
  523.         } else {
  524.             _ftp_fileTansfered = true;
  525.             updateStatus("\nCannot get remote file information");
  526.         }
  527.     }
  528.  
  529. //  uploading a file
  530.     public function upload(lf:String, rd:String, rf:String, fs:Number):Void {
  531.         updateStatus("\nUploading "+lf);
  532.         if (fs != undefined) {
  533.             _ftp_localFile = lf;
  534.             _ftp_remoteFile = rf;
  535.             _ftp_totalBytes = fs;
  536.             if (isNaN(_ftp_totalBytes)) {
  537.                 _ftp_totalBytes == null;
  538.                 updateStatus("\nCannot get local file size");
  539.                 return;
  540.             }
  541.             updateStatus("\nLocal file size: "+_ftp_totalBytes);
  542.             _ftp_fileTansfered = false;
  543.             if (_ftp != null) {
  544.                 //  creating the folder in the ftp folder
  545.                 _ftp.sendFile(_ftp_localFile, _ftp_remoteFile, mdm.ASYNC);
  546.             }
  547.             _ftp_siInterval = setInterval(this, "getTransferProgress", 500);
  548.         } else {
  549.             _ftp_fileTansfered = true;
  550.             updateStatus("\nCannot get local file size");
  551.         }
  552.     }
  553.  
  554.     public function close(Void):Void {
  555.         _ftp.close();
  556.     }
  557.  
  558.  
  559. /******************************************************************************
  560. * GET & SET
  561. ******************************************************************************/
  562.     public function get ftp_localFiles():Array {return _ftp_localFiles}
  563.     public function get ftp_localFile():String {return _ftp_localFile}
  564.     public function set ftp_remoteFiles(a:Array) {_ftp_remoteFiles = a}
  565.     public function get ftp_remoteFiles():Array {return _ftp_remoteFiles}
  566.     public function get ftp_root():String {return _ftp_root}
  567.     public function get local_root():String {return _ftp_localRoot}
  568.     public function get ftp():mdm.FTP {return _ftp}
  569. }   //END CLASS

Sources Sources File Unknown

Check the class. I have no time to provide an example nor to explain how it works. But it's kinda simple. You have a couple of helpfull public function, and in the ftpEventHandler function you can see that events are dispached. So just create your function like eg

Actionscript:
  1. myftp.fileReceived = function () {
  2. // code here
  3. }

I know as well that the way I used to call this function is not good. I could simply reference them in the var declaration and called them in my code and then not dispatching any events. I know. Maybe I will revised this code soon...
Anyway it works this way, so if you wanna use it you can...

Cheers

Related posts:

  1. MDM Zinc – Class FileSystemManager
  2. AS2 – Listening the event of a CLASS
  3. MDM Zinc – Class DateManager for ftp and filesystem
  4. AS2 – Vector Class

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Tags: , , ,

View Comments

  1. hi, i am very impressed by your work. i get very dizzy with all that code. but i have a question :)
    how i can list the ftp content in a tree component?
    if you can helpme i will be more than pleased.

    thanks.

  2. When scanning the ftp you can have an array of folder. So you jsut need to get this array and have your tree displaying it...
    Check the scanFolder function ( returns an array )
    ++

Leave a comment

blog comments powered by Disqus