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

📄 ftpupdatedlg.cpp

📁 自己改写的在WINCE上开发用的EVC++的FTP操作示例工程,希望能给相关人士提供帮助.
💻 CPP
字号:
// FTPUpdateDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FTPUpdate.h"
#include "FTPUpdateDlg.h"

#include <comdef.h>
#include <comutil.h>
#include <atlbase.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFTPUpdateDlg dialog

CFTPUpdateDlg::CFTPUpdateDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFTPUpdateDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFTPUpdateDlg)
	m_strTip = _T("");
	m_strIP = _T("192.168.18.70");
	m_nPort = 21;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFTPUpdateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFTPUpdateDlg)
	DDX_Text(pDX, IDC_EDIT1, m_strTip);
	DDX_Text(pDX, IDC_EDIT2, m_strIP);
	DDX_Text(pDX, IDC_EDIT3, m_nPort);
	DDV_MinMaxInt(pDX, m_nPort, 1, 65535);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFTPUpdateDlg, CDialog)
	//{{AFX_MSG_MAP(CFTPUpdateDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFTPUpdateDlg message handlers

BOOL CFTPUpdateDlg::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

	UpdateData(TRUE);

	// TODO: Add extra initialization here
	m_LogonInfo.SetHost(GetServerIP(),m_nPort);
	m_FTPClient.SetNotification(this);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CFTPUpdateDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_LogonInfo.SetHost(GetServerIP(),m_nPort);

	m_FTPClient.Login(m_LogonInfo);
	m_FTPClient.ChangeWorkingDirectory("/");

   nsFTP::TSpFTPFileStatusVector vFileList;
   m_FTPClient.List("/", vFileList,TRUE);
   for( nsFTP::TSpFTPFileStatusVector::iterator it=vFileList.begin(); it!=vFileList.end(); ++it )
      TRACE1("\n%s", (*it)->Name().GetString());
   m_FTPClient.DownloadFile("ADOTest.exe","/ADOTest.exe");
   m_FTPClient.Logout();
}

void CFTPUpdateDlg::OnSendCommand(CStringA strCommand)
{
   if( strCommand.GetLength()==0 )
      return;

   if(strCommand.GetLength() > 4 && strCommand.Mid(5) == "PASS ")
      WriteLine(_T("< PASS **********"), RGB(0, 0, 255));
   else
      WriteLine(_T("> ") + CString(strCommand.GetString()), RGB(0, 0, 255));
}

void CFTPUpdateDlg::OnResponse(CStringA strResponse)
{
   if( strResponse.GetLength()==0 )
      return;

   COLORREF crText = RGB(0, 150, 0);
   switch( strResponse.GetAt(0) )
   {
   case '4':
      crText = RGB(200, 200, 0);
      break;
   case '5':
      crText = RGB(255, 0, 0);
      break;
   }

   WriteLine(_T("< ") + CString(strResponse.GetString()), crText);
}

void CFTPUpdateDlg::OnInternalError(CStringA strErrorMsg, CStringA strFileName, DWORD dwLineNr)
{
   CString cszMsg = _T(""),strTemp;
   cszMsg += strErrorMsg.GetString();
   cszMsg += _T(" ==> Datei \"");
   cszMsg += strFileName.GetString();
   strTemp.Format(_T("\" (%d)"), dwLineNr);
   cszMsg += strTemp;
   WriteLine(cszMsg, RGB(255, 0, 0));
}

void CFTPUpdateDlg::WriteLine(const CString& cszLine, COLORREF crText)
{
	m_strTip += cszLine;
	m_strTip += _T("\r\n");
	UpdateData(FALSE);
}

CStringA CFTPUpdateDlg::GetServerIP()
{
	CStringA strIp = "";

	USES_CONVERSION;

	BSTR bstr = m_strIP.AllocSysString();
	strIp = W2A(bstr);
	SysFreeString(bstr);

	return strIp;
}

⌨️ 快捷键说明

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