⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zzzzzdlg.cpp

📁 这个程序是我编写的从FTP站点下载文件的wince程序
💻 CPP
字号:
// zzzzzDlg.cpp : implementation file
//

#include "stdafx.h"
#include "zzzzz.h"
#include "zzzzzDlg.h"
#include "ceinet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CZzzzzDlg dialog

CZzzzzDlg::CZzzzzDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CZzzzzDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CZzzzzDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CZzzzzDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CZzzzzDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CZzzzzDlg, CDialog)
	//{{AFX_MSG_MAP(CZzzzzDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZzzzzDlg message handlers

BOOL CZzzzzDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}



CString CZzzzzDlg::GetFtpFile(const TCHAR *ftpserver, const TCHAR *remotefile, const TCHAR *localfile)
{
	TCHAR   szCause[255];
    CString sCause;
    sCause.Format(_T(""));  
	
 
    try
    {
        //create the internet session 
        CCEInternetSession mysession;

        //get the ftp connection from internet session
        CCEFtpConnection* pFtpConn = mysession.GetFtpConnection(ftpserver);
        
        if(pFtpConn)
        {
           //we have successfully connected
          //try to find the remote file 

          CCEFtpFileFind finder(pFtpConn);
           
          BOOL bWorking = finder.FindFile(remotefile);
          AfxMessageBox(_T("find"));
          if(bWorking)
          { 
            // it exist .. so let's get it
            BOOL bGot = pFtpConn->GetFile(remotefile,localfile);
          }
          else
          {
            //something wrong with the file.. inform the user
            sCause.Format(_T("The File specified could not be found. ")
                       _T("Check your spelling and try again!!"));
          }

		}
        else
        {
          //could not connect
          sCause.Format(_T("Could not connect to ftp server!! \nPlease ")
                     _T("ensure you have correct address and access rights!"));
        }

        
   }
 
    catch(CException* error)
   {
        error->GetErrorMessage(szCause,254,NULL);
        sCause.Format(_T("%s"),szCause);
    }
    
 
    return (sCause);

}

void CZzzzzDlg::OnButton1() 
{
	CString sRet= GetFtpFile(_T("10.12.43.6"),21,NULL,NULL,_T("/incoming/usb/doc/TDS510usb User Guide Chinese.pdf"),_T("ResidentFlash\\TDS510usb10.pdf"));
    if(!sRet.IsEmpty())
    AfxMessageBox(sRet);
	AfxMessageBox(_T("1"));

	CString sRet1= GetFtpFile(_T("10.13.22.88"),52088,NULL,NULL,
		 _T("/control/TreeList.txt"),_T("ResidentFlash\\tree0.txt"));

	if(!sRet1.IsEmpty())
    AfxMessageBox(sRet1);
	

	
}

CString CZzzzzDlg::GetFtpFile(const TCHAR *ftpserver, WORD port,const TCHAR *username, 
							  const TCHAR *password, const TCHAR *remotefile, 
							  const TCHAR *localfile)
{

	TCHAR   szCause[255];
    CString sCause;
    sCause.Format(_T(""));  
	
  try
    {
        //启动一个session;
        CCEInternetSession mysession;
	    //连接FTP服务器;
        CCEFtpConnection* pFtpConn = mysession.GetFtpConnection(ftpserver,username,password,port,FALSE);
        //连接OK
        if(pFtpConn)
        {
          //在服务器上面寻找制定文件,
          CCEFtpFileFind finder(pFtpConn);
         
          BOOL bWorking = finder.FindFile(remotefile);
         
          if(bWorking)
          { 
           //找到文件;ok;下载;
            BOOL bGot = pFtpConn->GetFile(remotefile,localfile);
          }
          else
          {
            //否则没法找到文件;
            sCause.Format(_T("The File specified could not be found. ")
                       _T("Check your spelling and try again!!"));
          }

		}
        else
        {
          //否则无法连接
          sCause.Format(_T("Could not connect to ftp server!! \nPlease ")
                     _T("ensure you have correct address and access rights!"));
        }
     }
 //捕捉该异常
    catch(CException* error)
   {
        error->GetErrorMessage(szCause,254,NULL);
        sCause.Format(_T("%s"),szCause);
    }
    
  
    return (sCause);

}

void CZzzzzDlg::OnButton2() 
{
 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -