2024年3月9日发(作者:)

VC实现文件上传下载(FTP)

//连接ftp服务器

void CMyFtpDlg::OnConnect()

{

UpdateData(TRUE);

//新建对话

m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_I

NTERNET_ACCESS);

try

{

//新建连接对象

m_pFtpConnection=m_pInetSession->

GetFtpConnection(m_strServer,m_strUserName,

m_strPassword);

}

catch(CInternetException *pEx)

{

//获取错误

TCHAR szError[1024];

if(pEx-> GetErrorMessage(szError,1024))

AfxMessageBox(szError);

else

AfxMessageBox( "There was an exception ");

pEx-> Delete();

m_pFtpConnection=NULL;

return;

}