The FtpDeleteFile function deletes a file on an FTP server.
BOOL FtpDeleteFile(
HINTERNET hFtpSession,
LPCTSTR lpszFileName
);
This function takes two parameters:
hFtpSession: A handle to an FTP session, obtained from a call to FtpFindFirstFile or InternetConnect.lpszFileName: A pointer to a null-terminated string that contains the name of the file to be deleted.Deletes a file on an FTP server.
hFtpSessionA handle to an FTP session. This handle must be obtained from a successful call to FtpFindFirstFile or InternetConnect.
lpszFileNameA pointer to a null-terminated string that specifies the name of the file to be deleted. This can be a simple filename or a relative path.
Returns TRUE if the function is successful, or FALSE otherwise. To get a specific error message, call GetLastError.
Possible error codes include:
ERROR_INTERNET_EXTENDED_ERROR: An extended error occurred.ERROR_INTERNET_INVALID_URL: The URL specified is invalid.ERROR_INTERNET_SESSION_CLOSED: The FTP session has been closed.ERROR_INTERNET_OPERATION_CANCELLED: The operation was cancelled.The FtpDeleteFile function sends a DELE command to the FTP server to delete the specified file. The hFtpSession parameter must be a handle to an open FTP session. If hFtpSession was obtained by calling FtpFindFirstFile, the file to be deleted must be the one specified in the lpFindFileData parameter of that call.
If the file to be deleted is not found on the server, the function will likely return FALSE and GetLastError will return an appropriate error code (e.g., ERROR_FILE_NOT_FOUND, though FTP specific errors might differ).
It is important to ensure that the FTP session is properly closed after use by calling InternetCloseHandle on the handle returned by InternetConnect or FtpFindFirstFile.