package pl.maliboo.ftp.invokers { import pl.maliboo.ftp.errors.InvokeError; import pl.maliboo.ftp.Responses; import pl.maliboo.ftp.Commands; import pl.maliboo.ftp.FTPCommand; import pl.maliboo.ftp.events.FTPEvent; import pl.maliboo.ftp.core.FTPClient; import pl.maliboo.ftp.core.FTPInvoker; /** * Makes all the calls to the FTP server to create a new directory. * * @author Wijnand */ public class MakeDirInv extends FTPInvoker { private var newDirName:String; private var parentDir:String; /** * Creates a new directory on the remote host. * * @param client The ftp client we should be using to create the dir with. * @param newDirName The name of the new directory to create. * @param parentDir (Optional) The directory to create the new directory in. (Note: Always use a trailing slash!) */ public function MakeDirInv(client:FTPClient, newDirName:String, parentDir:String = "/") { this.newDirName = newDirName; this.parentDir = parentDir; super(client); } /** * @inheritDoc */ override protected function startSequence():void { sendCommand( new FTPCommand(Commands.MKD, parentDir + newDirName) ); } /** * @inheritDoc */ override protected function responseHandler(evt:FTPEvent):void { switch (evt.response.code) { // Successfully created dir. case Responses.PATHNAME_CREATED: // Dir already exists. case Responses.NOT_FOUND: var mkDirEvent:FTPEvent = new FTPEvent(FTPEvent.CREATE_DIR); release(mkDirEvent); break; default: releaseWithError(new InvokeError(evt.response.message)); break; } } /** * @inheritDoc */ override protected function cleanUp ():void { } } }