FtpDeleteFile

The FtpDeleteFile function deletes a file on an FTP server.

Syntax


BOOL FtpDeleteFile(
  HINTERNET hFtpSession,
  LPCTSTR   lpszFileName
);
                

Parameters

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.

Function

Deletes a file on an FTP server.

Parameters

hFtpSession

A handle to an FTP session. This handle must be obtained from a successful call to FtpFindFirstFile or InternetConnect.

lpszFileName

A 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.

Return Value

Returns TRUE if the function is successful, or FALSE otherwise. To get a specific error message, call GetLastError.

Possible error codes include:

Remarks

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.

See Also