VC文件上传和 FT实现

loading 分享 2026-8-25 下载文档

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

//连接ftp服务器

void CMyFtpDlg::OnConnect()

{

UpdateData(TRUE);

//新建对话

m_pInetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_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( \ was an exception \

pEx-> Delete();

m_pFtpConnection=NULL;

return;

}

m_pRemoteFinder = new CFtpFileFind(m_pFtpConnection);

//获得服务器根目录的所有文件并在列表框中显示

BrowseDir( \

}

//下载单个文件

void CMyFtpDlg::DownFile(FILEITEM fileItem)

{

if(fileItem.bDir == TRUE)

{

AfxMessageBox( \本程序暂时不支持下载整个文件夹,请选择文件下载 \

}

else

{

//格式化文件名

CString strLocalFile,strRemoteFile;

strRemoteFile.Format(

GetRoot(),fileItem.strFileName);

\\

strLocalFile.Format( \

//下载

if(m_pFtpConnection-> GetFile(strLocalFile,strLocalFile))

{

CString strMsg;

strMsg.Format( \下载文件%s成功! \

AfxMessageBox(strMsg);

}

}

}

//上传单个文件

void CMyFtpDlg::UpFile(FILEITEM fileItem)

{

if(fileItem.bDir == TRUE)

{

AfxMessageBox( \本程序暂时不支持上载整个文件夹,请选择文件上载 \

}

else

{

//格式化文件名

CString strLocalFile,strRemoteFile;

strRemoteFile.Format(

GetRoot(),fileItem.strFileName);

\\

strLocalFile.Format( \

//上传

if(m_pFtpConnection-> PutFile(strLocalFile,strLocalFile))

{

CString strMsg;

strMsg.Format( \上载文件%s成功! \

AfxMessageBox(strMsg);

}

} }


VC文件上传和 FT实现.doc 将本文的Word文档下载到电脑
搜索更多关于: VC文件上传和 FT实现 的文档
相关推荐
相关阅读