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 provide the capability to create and remove directories on an FTP server to which the application has the necessary privileges. If the application must log on to a server with a specific user name and password, the values can be used in InternetConnectwhen creating the FTP session handle.

The FtpCreateDirectoryfunction takes a valid FTP session handle and a NULL-terminated string that contains either a fully qualified path or a name relative to the current directory and creates a directory on the FTP server.

The following example shows two separate calls to FtpCreateDirectory. In both examples, hFtpSessionis the session handle created by the InternetConnectfunction, and the root directory is the current directory.

Copy Code
FtpCreateDirectory(hFtpSession, "test");
/* This will create the directory "test" in the current directory, 
   which is the root directory. */

FtpCreateDirectory(hFtpSession, "\test\example");
/* This will create the directory "example" in the test directory.
*/

The FtpRemoveDirectoryfunction takes a valid FTP session handle and a NULL-terminated string that contains either a fully qualified path or a name relative to the current directory and removes that directory from the FTP server.

The following example shows two sample calls to FtpRemoveDirectory. In both calls, hFtpSessionis the session handle created by the InternetConnectfunction, and the root directory is the current directory. There is a directory called "test" in the root directory and a directory called "example" in the "test" directory.

Copy Code
FtpRemoveDirectory(hFtpSession,"\test\example");
/* Removes the "example" directory and any files or directories
contained
in it from the "test" directory. */

FtpRemoveDirectory(hFtpSession, "test");
/* Removes the "test" directory and any files or directories
contained
in it from the root directory. */

The following example shows how to create the directory indicated by the string stored in the IDC_FTPEdit2edit box. The HINTERNEThandle hSecondarywas created by InternetConnectafter establishing an FTP session. DisplayDiris another function that is designed to enumerate the directory.

Copy Code
int WINAPI CreateDir(HWND hX)
{
	char strInFile[80];
	strInFile[0] = 0;
	GetDlgItemText(hX,IDC_FTPEdit2,strInFile,80);

	if (strlen(strInFile)==0)
	{
		MessageBox(hX,"Directory Name Must Be Specified","Create
Dir",MB_OK);
		return 0;
}
	else
	{
		if(!FtpCreateDirectory(hSecondary,strInFile))
		{
			ErrorOut(hX,GetLastError(),"Create Dir");
			return 0;
	}
		else
		{
			return DisplayDir(hX,INTERNET_FLAG_RELOAD);
	}
}
}

The following example shows how to delete the directory indicated by the IDC_FTPEdit2edit box. The HINTERNEThandle hSecondarywas created by InternetConnectafter establishing an FTP session. DisplayDiris another function that is designed to enumerate the directory.

Copy Code
int WINAPI RemoveDir(HWND hX)
{
	char strInFile[80];

	GetDlgItemText(hX,IDC_FTPEdit2,strInFile,80);

	if (strlen(strInFile)==0)
	{
		MessageBox(hX,"Directory Name Must Be Specified!","Remove
Dir",MB_OK);
		return 0;
}
	else
	{
		if(!FtpRemoveDirectory(hSecondary,strInFile))
		{
			ErrorOut(hX,GetLastError(),"Remove Dir");
			return 0;
	}
		else
		{
			MessageBox(hX,"Directory Deleted","Remove Dir",MB_OK);
			return DisplayDir(hX,INTERNET_FLAG_RELOAD);
	}
}
}

See Also

Concepts

FTP Sessions