FtpLib.h
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:5k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // Ftp.h: interface for the CFtp class.
- //
- //////////////////////////////////////////////////////////////////////
- #if !defined(AFX_FTP_H__5E33C9C5_D4AA_4CAB_972C_E5B142709716__INCLUDED_)
- #define AFX_FTP_H__5E33C9C5_D4AA_4CAB_972C_E5B142709716__INCLUDED_
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- #include "Winsock.h"
- #include "share.h"
- #include "FileQueue.h"
- #include "DeleteFileQueue.h"
- #define BUFFER_SIZE 4096
- #define RECEIVE_SIZE 4096
- #define MSGBOX_TITLE "error"
- #define DEFAULT_FTP_PORT 21
- #define ERROR_FTP_CODE 999
- //sub thread send to main thread .
- #define FTP_SERVER_REPLY_MSG WM_USER + 4001
- #define FTP_SEND_COMMAND_MSG WM_USER + 4002
- #define FTP_TRANSMIT_DATA_MSG WM_USER + 4003
- #define FTP_SERVER_DIR_LIST_MSG WM_USER + 4004
- #define FTP_STATUS_MSG WM_USER + 4005
- //server type
- #define UNIX_SERVER 1
- #define WINNT_SERVER 2
- #define LINUX_SERVER 3
- //main thread send to sub thread .
- #define FTP_SERVER_COMMAND_MSG WM_USER + 4502
- /*
- {
- ***** WPARAM *****:
- 0 : Quit .
- 1 : Send a command to thread . LPARAM is the command string address .
- 2 : Refurbish the current ftp directory .
- 3 : Get current ftp directory path .
- ***** LPARAM *****:
- }
- */
- //this struct mark a thread info.
- struct THREADINFO
- {
- HANDLE thread ; //thread handle
- DWORD threadid ; //thread id
- THREADINFO* pNext ; //next pointer .
- };
- //it a ftp file item info .
- //this struct can specify a ftp file .
- struct FTPITEM
- {
- char szName[128] ; //ftp file name
- char szSize[16] ; //ftp file size
- char szDate[16] ; //ftp file modify date
- char szTime[16] ; //ftp file modify time
- char szAttrib[16]; //ftp file attrib
- DWORD dwType ; //ftp file type ,is directory or file.
- FTPITEM* pNext ; //next pointer .
- } ;
- //this is the windows handle struct .
- //we use this handle change UI status .
- struct HWNDINFO
- {
- HWND hInfoWnd ;
- HWND hFtpDirListWnd ;
- HWND hWndJobWnd ;
- HWND hMultiDownUpWnd ;
- HWND hLocalDirListWnd ;
- } ;
- struct LISTINFO
- {
- HWND hFtpList ;
- HWND hLocalList ;
- HWND hCurJobList ;
- HWND hBkJobList ;
- HWND hGenius ;
- } ;
- ///////////////////////////////////////////////////////////////////////////////
- // Socket init function .
- ///////////////////////////////////////////////////////////////////////////////
- BOOL InitSocket ( );
- BOOL UnInitSocket( ) ;
- /***********************************************************
- ** @Description:
- ** this class encapsulation the ftp understratum function
- **
- ** @Note:
- **
- ** @Return:
- ** @Author: JHM
- ** e-mail: tablejiang@21cn.com
- ** Date: 2001 3 26
- ***********************************************************/
- class CFtpLib
- {
- public:
- CFtpLib();
- virtual ~CFtpLib();
- ////////////////////////////////////////////////////////////
- //*****************interface function ********************//
- ////////////////////////////////////////////////////////////
- public:
- SOCKET ConnectServer( LPCTSTR lpszHostName );
- BOOL CloseFtpConnect( SOCKET hSocket );
- UINT SendFtpCommand( LPSTR szCommandBuffer , SOCKET hSocket );
- UINT ReadDataCannelToFile( SOCKET hControlSocket , SOCKET hDataSocket , HANDLE hFile , __int64 iFileSize );
- UINT WriteDataCannelFromFile( SOCKET hControlSocket , SOCKET hDataSocket , HANDLE hFile );
- UINT ReadDataCannel( SOCKET hControlSocket , SOCKET hDataSocket , char* Buffer );
- SOCKET AcceptDataConnect( SOCKET hListenSocket );
- SOCKET CreateListenCannel( SOCKET hControlSocket );
- void SetStopSign( BOOL bRun );
- UINT GetSubItem( int* pos , char* word , int iwordsize , CString* string );
- ////////////////////////////////////////////////////////////
- //*****************interior function *********************//
- ////////////////////////////////////////////////////////////
- protected:
- int GetTransmitSpeed( DWORD dwStart , DWORD dwEnd , __int64 recData );
- BOOL AnonymousLogin( SOCKET hSocket );
- BOOL UserLogin( SOCKET hSocket , LPSTR szName , LPSTR szPass );
- BOOL SendMsgToParentWnd( LPSTR szMsg , BOOL bCommand );
- __int64 MyFileSeek( HANDLE hf , __int64 distance , DWORD MoveMethod );
- // BOOL SetTransmitFilePos( FTPFILEINFO* pFile , HANDLE hFile , SOCKET hSocket );
- UINT GetReplyCode( LPSTR lpszBuffer );
- int GetServerReply( SOCKET hSocket );
- BOOL IsReadyToRead( SOCKET hSocket );
- SOCKET PrepareDataCannel( SOCKET hListenSocket , SOCKET hControlSocket );
- SOCKET m_hDataSocket ;
- ////////////////////////////////////////////////////////////
- //***************** Data *********************************//
- ////////////////////////////////////////////////////////////
- public:
- char m_szFtpBuffer[BUFFER_SIZE] ;
- HWNDINFO m_hWndInfo ;
- BOOL m_bRun ;
- HWND m_hParentWnd ;
- };
- #endif // !defined(AFX_FTP_H__5E33C9C5_D4AA_4CAB_972C_E5B142709716__INCLUDED_)