Sample code for 30+ languages & platforms
Unicode C++

Delete FTP Directory Tree

See more FTP Examples

Delete an entire directory tree on an FTP server.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkFtp2W.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkFtp2W ftp;

    ftp.put_Hostname(L"ftp.yourftpserver.com");
    ftp.put_Username(L"****");
    ftp.put_Password(L"****");

    // Connect and login to the FTP server.
    success = ftp.Connect();
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    // Set the current remote directory to the root of
    // the tree to be deleted
    success = ftp.ChangeRemoteDir(L"/something");
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    // Delete the entire tree.  All sub-directories and files are deleted.
    success = ftp.DeleteTree();
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    // The /something directory still exists.  To delete it,
    // we move up one directory level and then delete it.
    success = ftp.ChangeRemoteDir(L"..");
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    success = ftp.RemoveRemoteDir(L"something");
    if (success != true) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    success = ftp.Disconnect();
    }