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
Hi, nice example, but i have some problems when i’m tring it to my app:
1) At “MakeDirInv.as” str 38:
override protected function startSequence():void
{
sendCommand( new FTPCommand(Commands.MKD, parentDir + newDirName) );
}
I have error massage about “MKD”
2) When I add EventListener, i haven’t “dirCreatedHandler”
client.addEventListener(FTPEvent.CREATE_DIR, dirCreatedHandler);
can u show dirCreatedHandler funk?
3) Can u add to blog full app, with can create folder no server? it will be perfect to dounload working example to understand how it works
Thank U!
Hi,
Thanks for commenting! 🙂
I think you have to add ‘public static const MKD:String = “MKD”;’ to the list of commands in pl.maliboo.ftp.Commands.
In my ‘dirCreatedHandler’ method I just have a trace statement and a call to another method that is specific to my app, the method signature looks like this:
‘private function dirCreatedHandler(event:FTPEvent):void’
Hope this helps,
Wijnand.