vc实现简单的ftp上传和下载功能
2010-12-21 10:11
696 查看
#include <afxinet.h>
void CFtpHandleDlg::OnOK()
{
// TODO: Add extra validation here
CInternetSession *m_pInternetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
CFtpConnection *m_pFtpConnection;
try{
m_pFtpConnection=m_pInternetSession->GetFtpConnection("127.0.0.1","123456","123456");
if(m_pFtpConnection != NULL)//链接成功
{
CFtpFileFind FtpFinder( m_pFtpConnection ) ;
CString FtpPath="/123/123.xls";
CString LocalPath ="D://456//456.xls";
if( !( m_pFtpConnection->GetFile( FtpPath, LocalPath, true, FILE_ATTRIBUTE_NORMAL , FTP_TRANSFER_TYPE_BINARY , 1) ) )
{
DWORD dErr = GetLastError() ;
CString sErr;
sErr.Format( "下载失败: ERROR %d" ,dErr ) ;
AfxMessageBox(sErr);
}
FtpPath="/123/456.xls";
if( !( m_pFtpConnection->PutFile( LocalPath, FtpPath, FTP_TRANSFER_TYPE_BINARY, 1) ) )
{
DWORD dErr = GetLastError() ;
CString sErr;
sErr.Format( "上传失败: ERROR %d" ,dErr ) ;
AfxMessageBox(sErr);
}
}
}catch(CInternetException *pEx){
TCHAR szError[1024];
if(pEx->GetErrorMessage(szError,1024))
AfxMessageBox(szError);
else
AfxMessageBox("There was an exception");
pEx->Delete();
m_pFtpConnection=NULL;
}
if(m_pFtpConnection != NULL)
{
m_pFtpConnection->Close();
delete m_pFtpConnection;
}
delete m_pInternetSession;
//CDialog::OnOK();
}
void CFtpHandleDlg::OnOK()
{
// TODO: Add extra validation here
CInternetSession *m_pInternetSession=new CInternetSession(AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
CFtpConnection *m_pFtpConnection;
try{
m_pFtpConnection=m_pInternetSession->GetFtpConnection("127.0.0.1","123456","123456");
if(m_pFtpConnection != NULL)//链接成功
{
CFtpFileFind FtpFinder( m_pFtpConnection ) ;
CString FtpPath="/123/123.xls";
CString LocalPath ="D://456//456.xls";
if( !( m_pFtpConnection->GetFile( FtpPath, LocalPath, true, FILE_ATTRIBUTE_NORMAL , FTP_TRANSFER_TYPE_BINARY , 1) ) )
{
DWORD dErr = GetLastError() ;
CString sErr;
sErr.Format( "下载失败: ERROR %d" ,dErr ) ;
AfxMessageBox(sErr);
}
FtpPath="/123/456.xls";
if( !( m_pFtpConnection->PutFile( LocalPath, FtpPath, FTP_TRANSFER_TYPE_BINARY, 1) ) )
{
DWORD dErr = GetLastError() ;
CString sErr;
sErr.Format( "上传失败: ERROR %d" ,dErr ) ;
AfxMessageBox(sErr);
}
}
}catch(CInternetException *pEx){
TCHAR szError[1024];
if(pEx->GetErrorMessage(szError,1024))
AfxMessageBox(szError);
else
AfxMessageBox("There was an exception");
pEx->Delete();
m_pFtpConnection=NULL;
}
if(m_pFtpConnection != NULL)
{
m_pFtpConnection->Close();
delete m_pFtpConnection;
}
delete m_pInternetSession;
//CDialog::OnOK();
}
相关文章推荐
- 最简单的在VC中用MFC中FTP下载功能的实现
- [Android中级]使用Commons-net-ftp来实现FTP上传、下载的功能
- FTP客户端--实现FTP文件的上传下载功能
- LIBCURL实现FTP上传下载功能
- 利用FTPClient类实现文件的上传下载功能
- FTP方式实现上传下载功能
- Java实现FTP上传下载功能
- 利用FTPClient类实现文件的上传下载功能
- struts2 实现简单的文件上传、下载功能
- 一个简单的FTP客户端 实现上传下载
- Java语言实现简单FTP软件------>上传下载管理模块的实现(十一)
- Winnet的ftp客户端实现上传、下载功能
- Java实现FTP上传下载功能
- C#实现FTP上传下载功能
- java中ftp上传、下载、重命名、删除功能实现
- Java语言实现简单FTP软件------>FTP软件效果图预览之下载功能(二)
- 使用struts2实现上传下载功能(附代码)。类似于ftp服务器。不止局限于本机的上传下载,其他机器也可使用此功能,服务器似的功能
- 简单使用Struts2 实现上传下载功能
- python socke ftp功能实现 shell命令,上传,下载
- 利用FTPClient类实现文件的上传下载功能