Brought to you by the |
The FTP functions deal with FTP file and directory manipulation and navigation.
BOOL FtpCreateDirectory( IN HINTERNET hFtpSession, IN LPCTSTR lpszDirectory );
Creates a new directory on the FTP server.
An application should use FtpGetCurrentDirectory to determine the remote site's current working directory, instead of assuming that the remote system uses a hierarchical naming scheme for directories.
The lpszDirectory parameter can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpCreateDirectory function translates the directory name separators to the appropriate character before they are used.
BOOL FtpDeleteFile( IN HINTERNET hFtpSession, IN LPCTSTR lpszFileName );
Deletes a file stored on the FTP server.
The lpszFile parameter can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpDeleteFile function translates the directory name separators to the appropriate character before they are used.
HINTERNET FtpFindFirstFile( IN HINTERNET hFtpSession, IN LPCTSTR lpszSearchFile OPTIONAL, OUT LPWIN32_FIND_DATA lpFindFileData, IN DWORD dwFlags IN DWORD dwContext );
Searches the specified directory of the given FTP session. File and directory entries are returned to the application in the WIN32_FIND_DATA structure.
This function enumerates both files and directories.
The FtpFindFirstFile function is similar to the Win32 FindFirstFile function. Note, however, that only one FtpFindFirstFile can occur at a time within a given FTP session. The enumerations, therefore, are correlated with the FTP session handle. This is because the FTP protocol allows only a single directory enumeration per session.
After calling FtpFindFirstFile and until calling InternetCloseHandle, the application cannot call FtpFindFirstFile again on a given FTP session handle. If this happens, calls to the FtpFindFirstFile function will fail with error code ERROR_FTP_TRANSFER_IN_PROGRESS.
After beginning a directory enumeration with FtpFindFirstFile, the InternetFindNextFile function can be used to continue the enumeration.
The InternetCloseHandle function is used to close the handle returned from FtpFindFirstFile. If the InternetCloseHandle function closes the handle before InternetFindNextFile fails with ERROR_NO_MORE_FILES, the directory enumeration will be terminated.
Because the FTP protocol provides no standard means of enumerating, some of the common information about files, such as file creation date and time, is not always available or correct. When this happens, FtpFindFirstFile and InternetFindNextFile fill in unavailable information with a "best guess" based on available information. For example, creation and last access dates will often be the same as the file's modification date.
The application cannot call FtpFindFirstFile between calls to FtpOpenFile and InternetCloseHandle.
See also FtpOpenFile, InternetCloseHandle, InternetFindNextFile, InternetSetStatusCallback
BOOL FtpGetCurrentDirectory( IN HINTERNET hFtpSession, OUT LPCTSTR lpszCurrentDirectory, IN OUT LPDWORD lpdwCurrentDirectory );
Retrieves the current directory for the specified FTP session.
If the lpszCurrentDirectory buffer is not large enough, lpdwCurrentDirectory receives the number of bytes required to retrieve the full, current directory name.
BOOL FtpGetFile( IN HINTERNET hFtpSession, IN LPCTSTR lpszRemoteFile, IN LPCTSTR lpszNewFile, IN BOOL fFailIfExists, IN DWORD dwFlagsAndAttributes, IN DWORD dwFlags, IN DWORD dwContext );
Retrieves a file from the FTP server and stores it under the specified file name, creating a new local file in the process.
The FtpGetFile function is a high-level routine that handles all the bookkeeping and overhead associated with reading a file from an FTP server and storing it locally. An application that needs to retrieve file data only or that requires close control over the file transfer should use the FtpOpenFile and InternetReadFile functions.
If the dwTransferType specifies FILE_TRANSFER_TYPE_ASCII, translation of the file data converts control and formatting characters to local equivalents. The default transfer is binary mode, where the file is downloaded in the same format as it is stored on the server.
Both lpszRemoteFile and lpszNewFile can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpGetFile function translates the directory name separators to the appropriate character before they are used.
HINTERNET FtpOpenFile( IN HINTERNET hFtpSession, IN LPCTSTR lpszFileName, IN DWORD fdwAccess, IN DWORD dwFlags, IN DWORD dwContext );
Initiates access to a remote file for writing or reading.
Value | Meaning |
FTP_TRANSFER_TYPE_ASCII | Transfer the file using FTP's ASCII (Type A) transfer method. Control and formatting information is converted to local equivalents. |
FTP_TRANSFER_TYPE_BINARY | Transfer the file using FTP's Image (Type I) transfer method. The file is transferred exactly as it exists with no changes. This is the default transfer method. |
The FtpOpenFile function should be used in the following situations:
After calling the FtpOpenFile function and until calling InternetCloseHandle, the application can call only InternetReadFile orInternetWriteFile, InternetCloseHandle, or the FtpFindFirstFile function. Calls to other FTP functions on the same FTP session will fail and set the error code 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 backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpOpenFile function translates the directory name separators to the appropriate character before they are used.
The InternetCloseHandle function is used to close the handle returned from FtpOpenFile. If the InternetCloseHandle function closes the handle before all the data has been transferred, the transfer is terminated.
BOOL FtpPutFile( IN HINTERNET hFtpSession, IN LPCTSTR lpszLocalFile, IN LPCTSTR lpszNewRemoteFile, IN DWORD dwFlags, IN DWORD dwContext );
Stores a file on the FTP server.
The FtpPutFile function is a high-level routine that handles all the bookkeeping and overhead associated with reading a file locally and storing it on an FTP server. An application that needs to send file data only, or that requires close control over the file transfer, should use the FtpOpenFile and InternetWriteFile functions.
If the dwTransferType specifies FILE_TRANSFER_TYPE_ASCII, translation of the file data converts control and formatting characters to local equivalents.
Both lpszNewRemoteFile and lpszLocalFile can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpPutFile function translates the directory name separators to the appropriate character before they are used.
BOOL FtpRemoveDirectory( IN HINTERNET hFtpSession, IN LPCTSTR lpszDirectory );
Removes the specified directory on the FTP server.
An application should use FtpGetCurrentDirectory to determine the remote site's current working directory, instead of assuming that the remote system uses a hierarchical naming scheme for directories.
The lpszDirectory parameter can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpRemoveDirectory function translates the directory name separators to the appropriate character before they are used.
BOOL FtpRenameFile( IN HINTERNET hFtpSession, IN LPCTSTR lpszExisting, IN LPCTSTR lpszNew );
Renames a file stored on the FTP server.
The lpszExisting and lpszNew parameters can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpRenameFile function translates the directory name separators to the appropriate character before they are used.
BOOL FtpSetCurrentDirectory( IN HINTERNET hFtpSession, IN LPCTSTR lpszDirectory );
Changes to a different working directory on the FTP server.
An application should use FtpGetCurrentDirectory to determine the remote site's current working directory, instead of assuming that the remote system uses a hierarchical naming scheme for directories.
The lpszDirectory parameter can be either partially or fully qualified file names relative to the current directory. A backslash (\) or forward slash (/) can be used as the directory separator for either name. The FtpSetCurrentDirectory function translates the directory name separators to the appropriate character before they are used.