Click here to Skip to main content
15,891,951 members
Articles / Desktop Programming / MFC

FTP Client Class

Rate me:
Please Sign up or sign in to vote.
4.85/5 (80 votes)
8 Dec 2012CPOL4 min read 774.3K   48.2K   246  
A non-MFC class to encapsulate the FTP protocol.
#pragma once

#include "Resource.h"
#include "FTPClient.h"
#include "afxcmn.h"
#include "afxwin.h"

namespace nsFTP
{
namespace nsView
{

class CFTPProgressDlg : public CDialog, public nsFTP::CFTPClient::CNotification
{
   DECLARE_MESSAGE_MAP()
   DECLARE_DYNAMIC(CFTPProgressDlg)
   enum { IDD = IDD_FTP_DLG_PROGRESS };
public:
   class CNotificationBase
   {
   public:
      virtual void OnAbort() {};
   };

   CFTPProgressDlg(CWnd* pParent = NULL);
   virtual ~CFTPProgressDlg();

   void AttachObserver(CNotificationBase* pObserver);
   void DetachObserver(CNotificationBase* pObserver);

protected:
   afx_msg void OnTimer(UINT nIDEvent);
   afx_msg void OnBnClickedCancel();
   CString GetTransferrate(int& iBytesPerSec);

   virtual BOOL OnInitDialog();
   virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

   virtual void OnBytesReceived(const TByteVector& vBuffer, long lReceivedBytes);
   virtual void OnBytesSent(const TByteVector& vBuffer, long lSentBytes);
   virtual void OnPreReceiveFile(const tstring& strSourceFile, const tstring& strTargetFile, long lFileSize);
   virtual void OnPreSendFile(const tstring& strSourceFile, const tstring& strTargetFile, long lFileSize);
   virtual void OnPostReceiveFile(const tstring& strSourceFile, const tstring& strTargetFile, long lFileSize);
   virtual void OnPostSendFile(const tstring& strSourceFile, const tstring& strTargetFile, long lFileSize);

private:
   CProgressCtrl     m_ctrlProgress;
   CAnimateCtrl      m_ctrlAnimate;
   CStatic           m_ctrlFileStatus;
   CStatic           m_ctrlSourceFile;
   CStatic           m_ctrlTargetFile;
   nsHelper::CTimer  m_Timer;
   typedef std::set<CNotificationBase*> TObserverSet;
   TObserverSet m_setObserver;
};

};
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions