vc-ftp上传文件例子教程

直接上代码吧:

void CftptestDlg::OnBnClickedButtonGo()
{
	// TODO: 在此添加控件通知处理程序代码
	//开始上传
	CInternetSession CIS;
	CFtpConnection *ftp = CIS.GetFtpConnection("server","username","ps",21);
	//建立文件夹
	//ftp->CreateDirectory("fffff");
	CString strLocalFile;
	CFile fUpload("test.zip",CFile::modeRead|CFile::typeBinary);
	//要上传的文件的大小
	int nFileLength = fUpload.GetLength();
	fUpload.Read(strLocalFile.GetBuffer(nFileLength),nFileLength);
	strLocalFile.ReleaseBuffer(nFileLength);
	fUpload.Close();
	//远程ftp文件
	CInternetFile *CIF = ftp->OpenFile("test.zip",GENERIC_WRITE,FTP_TRANSFER_TYPE_BINARY,1);
	CIF->Write(strLocalFile.GetBuffer(nFileLength),nFileLength);
	CIF->Close();
}

Leave a Reply