Sample code for 30+ languages & platforms
DataFlex

Remove a Remote FTP Directory (RMD)

See more FTP Examples

Demonstrates the Chilkat Ftp2.RemoveRemoteDir method, which removes a remote directory. The only argument is the remote directory path.

Background: Most FTP servers refuse to remove a directory that is not empty, so clearing a populated folder means deleting its contents first — or using DeleteTree to clear the subtree and then removing the now-empty directory. After a removal, the cached indexed listing is not refreshed automatically; call ClearDirCache before relying on the old cache again.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoFtp
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the Ftp2.RemoveRemoteDir method, which removes a remote directory.  The only
    //  argument is the remote directory path.

    Get Create (RefClass(cComChilkatFtp2)) To hoFtp
    If (Not(IsComObjectCreated(hoFtp))) Begin
        Send CreateComObject of hoFtp
    End

    Set ComHostname Of hoFtp To "ftp.example.com"
    Set ComUsername Of hoFtp To "myFtpLogin"

    //  Normally you would not hard-code the password in source.  You should instead obtain it
    //  from an interactive prompt, environment variable, or a secrets vault.
    Set ComPassword Of hoFtp To "myPassword"

    Get ComConnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComChangeRemoteDir Of hoFtp "public_html" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  FTP servers generally require the directory to be empty before it can be removed.
    Get ComRemoveRemoteDir Of hoFtp "uploads/old" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Directory removed."

    Get ComDisconnect Of hoFtp To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoFtp To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure