Accessing the FTP Protocol

Wininet.dll and the corresponding Wininet.lib do not include the FTP APIs. To develop FTP applications on a version of the Windows CE OS that does not export FTP APIs from the Wininet.dll, you can use Winsock.. FTP APIs are included in the emulation library, Wininetm.lib, and will work in the emulation environment. You can use the FTP APIs with Windows CE version 2.12 which is included in Wininet.dll and Wininet.lib.

The following illustration shows the FTP functions dependent on the FTP session HINTERNET returned by InternetConnect. The shaded boxes represent functions that return HINTERNETs and the plain boxes represent functions that use the HINTERNET created by the function on which they depend.

The FtpCreateDirectory, FtpDeleteFile, FtpGetCurrentDirectory, FtpGetFile, FtpPutFile, FtpRemoveDirectory, FtpRenameFile, and FtpSetCurrentDirectory functions use the HINTERNET handle created by InternetConnect.

The following illustration shows the two FTP functions that return HINTERNET handles and the functions dependent on the HINTERNET handles created by them. The shaded boxes represent functions that return HINTERNET handles, while the plain boxes represent functions that use the HINTERNET handle created by the function on which they depend.

InternetFindNextFile is dependent on the HINTERNET handle created by FtpFindFirstFile, and InternetReadFile uses the HINTERNET handle created by FtpOpenFile.

Use WinInet to perform the following tasks on an FTP server:

    To access an FTP server with WinInet

  1. Call InternetOpen to initialize an Internet handle.

    InternetOpen creates the root HINTERNET handle that is used to establish the FTP session. The HINTERNET Internet handle is used by all subsequent functions.

  2. Call InternetConnect to create an FTP session.

    When calling InternetConnect specify INTERNET_DEFAULT_FTP_PORT for the nServerPort parameter and INTERNET_SERVICE_FTP for the dwService parameter.

    This function uses the handle returned by InternetOpen to create a specific FTP session. InternetConnect initializes an FTP session for the specified site, using the arguments passed to it and creates HINTERNET that is a branch off the root handle. In the case of an FTP session, InternetConnect attempts to establish a connection to the specified site.

  3. Call FtpGetFile or FtpFindFirstFile.

    InternetConnect returns a handle that subsequent functions can use, such as FtpGetFile or FtpFindFirstFile.

    Use the InternetFindNextFile function with FtpFindFirstFile to find the next file in a file search, using the search parameters and HINTERNET handle from FtpFindFirstFile.

    To complete a file search, continue to call InternetFindNextFile using the HINTERNET handle returned by FtpFindFirstFile until function fails with the extended error message ERROR_NO_MORE_FILES. To get the extended error data, call the GetLastError function.

  4. Call InternetCloseHandle to close the FTP session created by calling InternetConnect.
  5. Call InternetCloseHandle to close the handle created by calling InternetOpen.

Note Applications must specify a directory relative to the current directory or include the full directory path.