FTP Sessions

The Windows Internet Services (WinInet) functions enable applications to navigate and manipulate directories and files on an FTP server.

To begin an FTP session, use InternetConnect to create the FTP session handle to be used by the FTP functions provided with the WinInet functions.

The WinInet functions provide the following actions on an FTP server:

  • Navigation between directories.
  • Enumerating, creating, removing, and renaming directories.
  • Renaming, uploading, downloading, and deleting files.

Navigation is provided by the FtpGetCurrentDirectory and FtpSetCurrentDirectory functions. These functions utilize the FTP session handle created by a previous call to InternetConnect to determine which directory the application is currently in, or to change to a different subdirectory.

Directory enumeration is performed by using the FtpFindFirstFile and InternetFindNextFile functions. FtpFindFirstFile uses the FTP session handle created by InternetConnect to find the first file that matches the given search criteria and returns a handle to continue the directory enumeration. InternetFindNextFile uses the handle returned by FtpFindFirstFile to return the next file that matches the original search criteria. The application should continue to call InternetFindNextFile until there are no more files left in the directory.

Use the FtpCreateDirectory function to create new directories. This function uses the FTP session handle created by InternetConnect and creates the directory specified by the string passed to the function. The string can contain a directory name relative to the current directory, or a fully qualified directory path.

To rename either files or directories, the application can call FtpRenameFile. This function replaces the original name with the new name passed to the function. The name of the file or directory can be relative to the current directory, or a fully qualified name.

To upload or place files on an FTP server, the application can use either FtpPutFile or FtpOpenFile (along with InternetWriteFile). FtpPutFile can be used if the file already exists locally, while FtpOpenFile and InternetWriteFile can be used if data needs to be written to a file on the FTP server.

To download or get files, the application can use either FtpGetFile or FtpOpenFile (with InternetReadFile). FtpGetFile is used to retrieve a file from an FTP server and store it locally, while FtpOpenFile and InternetReadFile can be used to control where the downloaded information is going (for example, the application could display the information in an edit box).

Delete files on an FTP server by using the FtpDeleteFile function. This function removes a file name that is relative either to the current directory or to a fully qualified file name from the FTP server. FtpDeleteFile requires an FTP session handle returned by InternetConnect.

For more information about FTP sessions, see the following topics:

FTP Function Handles

Using the WinInet Functions for FTP Sessions

Starting an FTP Session

Enumerating Directories

Navigating Directories

Manipulating Directories on an FTP Server

Retrieving Files from an FTP Server

Placing Files on an FTP Server

Deleting Files from an FTP Server

Renaming Files and Directories on an FTP Server

HTTP Authentication

Server Authentication

Proxy Authentication

Handling HTTP Authentication

See Also

Windows Internet Services (WinInet)WinInet Registry Settings

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.