FtpOpenFile

This function initiates access to a remote file for writing or reading.

BOOL WINAPI FtpOpenFile(
HINTERNET hConnect, 
LPCTSTR lpszFileName, 
DWORD dwAccess, 
DWORD dwFlags, 
DWORD dwContext);

Parameters

  • hConnect
    [in] Valid handle to an FTP session.

  • lpszFileName
    [in] Long pointer to a null-terminated string that contains the name of the file to access on the remote system.

  • dwAccess
    [in] Value that determines how the file will be accessed. This can be GENERIC_READ or GENERIC_WRITE, but not both.

  • dwFlags
    [in] Specifies the conditions under which the transfers occur. The application should select one transfer type and flags that control file caching. The transfer type can be one of the following values:

    Value Description
    FTP_TRANSFER_TYPE_ASCII Transfers the file using FTP ASCII, Type A, transfer method. Control and formatting data is converted to local equivalents.
    FTP_TRANSFER_TYPE_BINARY Transfers the file using FTP Image, Type I, transfer method. The file is transferred exactly as it exists with no changes. This is the default transfer method.
    FTP_TRANSFER_TYPE_UNKNOWN Defaults to FTP_TRANSFER_TYPE_BINARY.
    INTERNET_FLAG_TRANSFER_ASCII Transfers the file as ASCII.
    INTERNET_FLAG_TRANSFER_BINARY Transfers the file as binary.

    One or more of the values described in the following table are used by an application to control file caching.

    Value Description
    INTERNET_FLAG_DONT_CACHE Does not cache the data, either locally or in gateways. Identical to the preferred value INTERNET_FLAG_NO_CACHE_WRITE.
    INTERNET_FLAG_HYPERLINK Forces a reload if there was no Expires time and no Last-Modified time returned by the server when determining whether to reload the item from the network.
    INTERNET_FLAG_MUST_CACHE_REQUEST Causes a temporary file to be created if the file cannot be cached. Identical to the preferred value INTERNET_FLAG_NEED_FILE.
    INTERNET_FLAG_NEED_FILE Causes a temporary file to be created if the file cannot be cached.
    INTERNET_FLAG_NO_CACHE_WRITE Does not cache the data, either locally or in gateways.
    INTERNET_FLAG_RELOAD Forces a download of the requested file, object, or directory listing from the origin server, not from the cache.
    INTERNET_FLAG_RESYNCHRONIZE Causes the FTP resource to be reloaded from the server.
  • dwContext
    [in] Specifies an application-defined value that associates this search with application data. This is only used if the application has already called InternetSetStatusCallback to set up a status callback function. All status requests are handled synchronously.

Return Values

A handle indicates success. NULL indicates failure. To get extended error data, call GetLastError.

Remarks

Inetftp.dll is available only for Intel x86 processors.

FtpOpenFile should be used in the following situations:

An application has data it needs to send to an FTP server to be created as a file on the FTP server, but the application does not have a local file containing the data. After the file is opened with FtpOpenFile, the application uses InternetWriteFile to send the FTP file data to the server.

An application needs to retrieve a file from the server into application-controlled memory, instead of writing the file to disk. The application uses InternetReadFile after using FtpOpenFile to open the file.

An application needs a fine level of control over a file transfer. For example, the application may need to display a progress indicator when downloading a file to indicate to the user that the file transfer is, or is not, proceeding correctly.

After calling FtpOpenFile and until calling InternetCloseHandle, all other calls to FTP functions on the same FTP session handle will fail and set the error message to ERROR_FTP_TRANSFER_IN_PROGRESS.

Only one file can be open in a single FTP session. Therefore, no file handle is returned and the application simply uses the FTP session handle when necessary.

The lpszFile parameter can be either partially or fully qualified file names relative to the current directory. A backward slash (\) or forward slash (/) can be used as the directory separator for either name. FtpOpenFile translates the directory name separators to the appropriate character before they are used.

The InternetCloseHandle function is used to close the handle returned by FtpOpenFile. If InternetCloseHandle closes the handle before all the data has been transferred, the transfer is terminated.

Requirements

Runs on Versions Defined in Include Link to
Windows CE OS 2.0 and later Wininet.h   Wininet.lib

Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

See Also

GetLastError, InternetCloseHandle, InternetReadFile, InternetSetStatusCallback, InternetWriteFile

 Last updated on Tuesday, July 13, 2004

© 1992-2000 Microsoft Corporation. All rights reserved.