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

There are two methods for placing a file on an FTP server using the Windows Internet Services (WinInet) functions:

An application that must send data to an FTP server, but does not have a local file containing all the data, should use FtpOpenFileto create and open a file on the FTP server. The application then can use InternetWriteFileto upload the information to the file.

If the file already exists locally, the application can use FtpPutFileto upload the file to the FTP server. FtpPutFileperforms all actions associated with uploading a local file to a remote FTP server.

The following example shows how to place the file indicated by the IDC_FTPEdit2edit box on the FTP server, using the file name specified by the IDC_FTPEdit3edit box. The HINTERNEThandle hSecondarywas created by InternetConnectafter establishing an FTP session.

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

	if ((strlen(strOutFile)==0) || (strlen(strInFile)==0))
	{
		MessageBox(hX,"Target File or Destination File
Missing","Put File",MB_OK);
		return 0;
}
	else
	{
		intTransType = MessageBox(hX,
			"Do you want to upload in ASCII (Default:Binary)?",
			"Put File",MB_YESNO);

		if (intTransType==IDYES)
		{
			if(!FtpPutFile(hSecondary,strInFile,strOutFile,
				FTP_TRANSFER_TYPE_ASCII,0))
			{
				ErrorOut(hX,GetLastError(),"Get File");
				return 0;
		}
			else
			{
				MessageBox(hX,"ASCII Transfer Complete","Put
File",MB_OK);
				return 1;
		}
	}
		else
		{
			if(!FtpPutFile(hSecondary,strInFile,strOutFile,
				FTP_TRANSFER_TYPE_BINARY,0))
			{
				ErrorOut(hX,GetLastError(),"Get File");
				return 0;
		}
			else
			{
				MessageBox(hX,"Binary Transfer Complete","Get
File",MB_OK);
				DisplayDir(hX,INTERNET_FLAG_RELOAD);
				return 1;
		}
	}
}
}//end

See Also

Concepts

FTP Sessions