ftp ftp

ftp

 

CInternetSession* m_pInetSession;
 CFtpConnection*   m_pFtpConnection;

//连接服务器的函数

BOOL CftpClientDlg::connnect()
{
 m_pInetSession = new CInternetSession( AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
 try{
  m_pFtpConnection = m_pInetSession->GetFtpConnection(L"127.0.0.1",L"chentongxin",L"tongxin",21);
  AfxMessageBox(L"服务器连接成功");
 }
 catch(CInternetException *pEx){
  
  TCHAR szError[1024] = {0};
  if(pEx->GetErrorMessage(szError,1024))
   AfxMessageBox(szError);
  else
   AfxMessageBox(L"服务器连接失败");
  pEx->Delete();
  m_pFtpConnection = NULL;

  return FALSE;
 }
 return TRUE;
}

//上传文件
BOOL CftpClientDlg::putFile()
{
 if(m_pFtpConnection->PutFile(_T("e:/test.txt"),_T("test.txt"))){
  //第一个参数为本地文件的地址,第二个为服务器端文件的地址
  AfxMessageBox(_T("发送成功!"));
  return TRUE;
 }
 else{
  AfxMessageBox(_T("发送失败!"));
  return FALSE;
 }
}

//下载文件
BOOL CftpClientDlg::getFile()
{
 if(m_pFtpConnection->GetFile(_T("afa.txt"),_T("e:/a.txt"))){
  //第一个参数为本地文件的地址,第二个为服务器端文件的地址
  AfxMessageBox(_T("下载成功!"));
  return TRUE;
 }
 else{
  AfxMessageBox(_T("下载失败!"));
  return FALSE;
 }
 return TRUE;
}

//关闭连接
BOOL CftpClientDlg::disconnect()
{
 if(m_pFtpConnection != NULL)
 {
  m_pFtpConnection->Close();
  delete m_pFtpConnection;
 }
 delete m_pInetSession;
 return TRUE;
}

CInternetSession* m_pInetSession;
 CFtpConnection*   m_pFtpConnection;

//连接服务器的函数

BOOL CftpClientDlg::connnect()
{
 m_pInetSession = new CInternetSession( AfxGetAppName(),1,PRE_CONFIG_INTERNET_ACCESS);
 try{
  m_pFtpConnection = m_pInetSession->GetFtpConnection(L"127.0.0.1",L"chentongxin",L"tongxin",21);
  AfxMessageBox(L"服务器连接成功");
 }
 catch(CInternetException *pEx){
  
  TCHAR szError[1024] = {0};
  if(pEx->GetErrorMessage(szError,1024))
   AfxMessageBox(szError);
  else
   AfxMessageBox(L"服务器连接失败");
  pEx->Delete();
  m_pFtpConnection = NULL;

  return FALSE;
 }
 return TRUE;
}

//上传文件
BOOL CftpClientDlg::putFile()
{
 if(m_pFtpConnection->PutFile(_T("e:/test.txt"),_T("test.txt"))){
  //第一个参数为本地文件的地址,第二个为服务器端文件的地址
  AfxMessageBox(_T("发送成功!"));
  return TRUE;
 }
 else{
  AfxMessageBox(_T("发送失败!"));
  return FALSE;
 }
}

//下载文件
BOOL CftpClientDlg::getFile()
{
 if(m_pFtpConnection->GetFile(_T("afa.txt"),_T("e:/a.txt"))){
  //第一个参数为本地文件的地址,第二个为服务器端文件的地址
  AfxMessageBox(_T("下载成功!"));
  return TRUE;
 }
 else{
  AfxMessageBox(_T("下载失败!"));
  return FALSE;
 }
 return TRUE;
}

//关闭连接
BOOL CftpClientDlg::disconnect()
{
 if(m_pFtpConnection != NULL)
 {
  m_pFtpConnection->Close();
  delete m_pFtpConnection;
 }
 delete m_pInetSession;
 return TRUE;
}

猜你喜欢

转载自www.cnblogs.com/mjgw/p/12347827.html
FTP