Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

The Windows Internet Services (WinInet) functions FtpGetCurrentDirectoryand FtpSetCurrentDirectoryhandle directory navigation.

FtpGetCurrentDirectoryreturns the application's current directory on the FTP server. The directory path from the root directory on the FTP server is included.

FtpSetCurrentDirectorychanges the working directory on the server. The directory information passed to FtpSetCurrentDirectorycan be either a partially or fully qualified path name relative to the current directory. For example, if the application is currently in the directory public\info and the path is ftp/example, FtpSetCurrentDirectorychanges the current directory to public\info\ftp\example.

The following example shows how to use the FTP session handle hSecondary, which is returned by InternetConnect. The new directory name is stored in the IDC_FTPEdit2edit box. Before the actual change is made, the function retrieves the current directory and stores it in the same edit box. DisplayDiris another function that is designed to enumerate the directory.

Copy Code
int WINAPI ChangeDir(HWND hX)
{
	DWORD testsz = 320;
	LPSTR lpszUrlBuffer; 		// Buffer to hold the URL
	LPSTR lpszDirList;

	lpszUrlBuffer = new char[testsz];
	if(lpszUrlBuffer)
	{
	 *lpszUrlBuffer=0;
}
	GetDlgItemText(hX,IDC_FTPEdit2,(LPSTR)lpszUrlBuffer,testsz);
	lpszDirList = new char[testsz];
	if
(!FtpGetCurrentDirectory(hSecondary,(LPSTR)lpszDirList,&testsz))
	{
		ErrorOut(hX,GetLastError(),"Change Dir");
}
	else
		SetDlgItemText(hX,IDC_FTPEdit2,(LPSTR)lpszDirList);

	delete(lpszDirList);

	if (!(FtpSetCurrentDirectory(hSecondary,lpszUrlBuffer)))
	{
		ErrorOut(hX,GetLastError(),"InternetConnect");
		delete(lpszUrlBuffer);
		SetDlgItemText(hX,IDC_FTPEdit2,(LPSTR)lpszUrlBuffer);
		DisplayDir(hX,INTERNET_FLAG_RELOAD);
		return 0;
}
	else
	{
		delete(lpszUrlBuffer);
		return DisplayDir(hX,0);
}
}

See Also

Concepts

FTP Sessions