I’m messing around with Flex FTP at the moment and found that there is no way yet to create a directory on the FTP server. I had a quick look through the code on how the other FTP actions were implemented. Being surprised with the nice setup of the code I had quite easily added the “make directory” action and got it working properly. You can download my MakeDirInv class here: http://ansuz.nl/toys/randomcode/MakeDirInv.as
All you need to do after that is patch the FTPClient class by adding the following method.
- /**
- * Creates a directory on the remote host.
- *
- * @param newDirName The name of the new directory to create.
- * @param parentDir (Optional) The directory to create the new directory in.
- */
- public function makeDir(newDirName:String, parentDir:String = "/"):void {
- trace("FTPClient.makeDir(newDirName, parentDir)");
- invoke(new MakeDirInv(this, newDirName, parentDir));
- }
Once you’ve done that, you’re ready to create directories on the FTP server you’re connected to, see the example below.
- ftpClient.addEventListener(FTPEvent.CREATE_DIR, dirCreatedHandler);
- ftpClient.makeDir("myNewDir", "/someSubDir/");
PS: This isn’t fully tested yet, so do let me know if you find some bugs.
Links