| INT WINAPI FtpOpenDirectory(
|
| |
HCLIENT hClient, |
|
| |
LPCTSTR lpszDirectory |
|
| );
|
The FtpOpenDirectory function opens the specified
directory on the server.
Parameters
- hClient
- Handle to the client session.
- lpszDirectory
- Pointer to the name of the directory that will be opened. The
format of the directory name must match the filename conventions
used by the server. If a NULL pointer or an empty string is
specified, then the current working directory is opened.
Return Value
If the function succeeds, the return value is the server result
code. If the function fails, the return value is FTP_ERROR. To get
extended error information, call FtpGetLastError.
Remarks
The FtpOpenDirectory function opens the specified
directory on the server using the LIST command. The contents of the
directory can be read using the FtGetFirstFile and
FtpGetNextFile functions. The directory listing is returned
on the data channel in one of several different formats. The
library can recognize listing formats generated by UNIX, VMS and
Windows servers, as well as those of other servers which emulate
one of those common formats. Once the complete directory listing
has been read, the directory must be closed by calling the
FtpCloseDirectory function.
Because the directory listing is returned on the data channel, a
file transfer cannot be performed while the directory is in the
process of being read by the client. Applications which need to
collect a list of files to download should first open the
directory, read the contents and store the file names in an array.
After the directory has been closed, the application can then start
transferring the files to the local system.
Some servers may not support file listings for any directory
other than the current working directory. If an error is returned
when specifying a directory name, try changing the current working
directory using the FtpChangeDirectory function and then
call this function again, passing NULL or an empty string as the
lpszDirectory parameter.
To obtain a list of all files in a directory using a single
function call, use the FtpEnumFiles function. If the server
lists files in a format that is not recognized by the library, the
FtpGetFileList function can be used to obtain an unparsed
file listing from the server.
Example
if (FtpOpenDirectory(hClient, NULL) != FTP_ERROR)
{
FTPFILESTATUS ftpFile;
BOOL bResult;
bResult = FtpGetFirstFile(hClient, &ftpFile);
while (bResult)
{
// The ftpFile structure contains information about the file
bResult = FtpGetNextFile(hClient, &ftpFile);
}
FtpCloseDirectory(hClient);
}
Requirements
Client: Requires Windows 7, Windows Vista or Windows
XP.
Server: Requires Windows Server 2008 or Windows Server
2003.
Header: Include cstools7.h.
Library: Use csftpav7.lib.
Unicode: Implemented as Unicode and ANSI versions.
See Also
FtpChangeDirectory,
FtpCloseDirectory, FtpEnumFiles, FtpGetDirectoryFormat, FtpGetFileList, FtpGetFileStatus, FtpGetFirstFile, FtpGetNextFile, FtpSetDirectoryFormat
|