Deleting Files from an FTP Server

To delete a file from an FTP server, an application can use the FtpDeleteFile function. The calling application must have the necessary privileges to delete a file from the FTP server.

The following example shows how to delete the file indicated by the IDC_FTPEdit2 edit box. The HINTERNET handle hSecondary was created by InternetConnect after establishing an FTP session. DisplayDir is another function that is designed to enumerate the directory.

int WINAPI DeleteFile(HWND hX)
{
    char strInFile[80];
    strInFile[0] = 0;
    GetDlgItemText(hX,IDC_FTPEdit2,strInFile,80);

    if (strlen(strInFile)==0)
    {
        MessageBox(hX,"File Name Must Be Specified.","Remove Dir",MB_OK);
        return 0;
    }
    else
    {
        if(!FtpDeleteFile(hSecondary,strInFile))
        {
            ErrorOut(hX,GetLastError(),"Remove Dir");
            return 0;
        }
        else
        {
            MessageBox(hX,"File Deleted","Remove Dir",MB_OK);
            return DisplayDir(hX,INTERNET_FLAG_RELOAD);
        }
    }
}//end

See Also

FTP Sessions | Windows Internet Services (WinInet)

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.