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

Delete a Remote FTP File (DELE)

See more FTP Examples

Demonstrates the Chilkat Ftp2.DeleteRemoteFile method, which deletes a remote file. The only argument is the remote file path, relative to the current directory or absolute.

Background: Deletion is immediate and permanent — FTP has no trash or undo — so a job that removes files should be certain of the path first. Whether it is allowed depends on the account's permissions on the file and its containing directory. Note that a successful delete does not refresh the cached indexed listing.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkFtp2W.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the Ftp2.DeleteRemoteFile method, which deletes a remote file.  The only argument
    //  is the remote file path (relative to the current directory or absolute).

    CkFtp2W ftp;

    ftp.put_Hostname(L"ftp.example.com");
    ftp.put_Username(L"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.
    ftp.put_Password(L"myPassword");

    success = ftp.Connect();
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    success = ftp.ChangeRemoteDir(L"public_html");
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    success = ftp.DeleteRemoteFile(L"uploads/obsolete.tmp");
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }

    wprintf(L"File deleted.\n");

    success = ftp.Disconnect();
    if (success == false) {
        wprintf(L"%s\n",ftp.lastErrorText());
        return;
    }
    }