ftp.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // ftp.h : Declaration of the Cftp
  19. #ifndef __FTP_H_
  20. #define __FTP_H_
  21. //#include "../resource.h" // main symbols
  22. #include "winsock.h"
  23. #include "stdio.h"
  24. #include "WWDownload/ftpdefs.h"
  25. // FTP server return codes. See RFC 959
  26. #define FTPREPLY_SERVEROK 220
  27. #define FTPREPLY_PASSWORD 331
  28. #define FTPREPLY_LOGGEDIN 230
  29. #define FTPREPLY_PORTOK 200
  30. #define FTPREPLY_TYPEOK 200
  31. #define FTPREPLY_RESTARTOK 350
  32. #define FTPREPLY_CWDOK 250
  33. #define FTPREPLY_OPENASCII 150
  34. #define FTPREPLY_OPENBINARY 150
  35. #define FTPREPLY_COMPLETE 226
  36. #define FTPREPLY_CONTROLCLOSED 421
  37. // Temporary download file name
  38. #define FTP_TEMPFILENAME "..\\__~DOWN_L~D"
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Cftp
  41. class Cftp
  42. {
  43. private:
  44. friend class CDownload;
  45. int m_iCommandSocket; // Socket for commands
  46. int m_iDataSocket; // Socket for data
  47. struct sockaddr_in m_CommandSockAddr; // Address for commands
  48. struct sockaddr_in m_DataSockAddr; // Address for data
  49. int m_iFilePos; // Byte offset into file
  50. int m_iBytesRead; // Number of bytes downloaded
  51. int m_iFileSize; // Total size of the file
  52. char m_szRemoteFilePath[128];
  53. char m_szRemoteFileName[128];
  54. char m_szLocalFilePath[128];
  55. char m_szLocalFileName[128];
  56. char m_szServerName[128];
  57. char m_szUserName[128];
  58. char m_szPassword[128];
  59. FILE * m_pfLocalFile;
  60. int m_iStatus;
  61. int m_sendNewPortStatus;
  62. int m_findStart;
  63. int SendData( char * pData, int iSize );
  64. int RecvData( char * pData, int iSize );
  65. int SendNewPort();
  66. int OpenDataConnection();
  67. void CloseDataConnection();
  68. int AsyncGetHostByName( char * szName, struct sockaddr_in &address );
  69. // Convert a local filename into a temp filename to download into
  70. void GetDownloadFilename( const char* localname, char* downloadname);
  71. void CloseSockets(void);
  72. void ZeroStuff(void);
  73. public:
  74. Cftp();
  75. virtual ~Cftp();
  76. public:
  77. HRESULT ConnectToServer(LPCSTR szServerName);
  78. HRESULT DisconnectFromServer();
  79. HRESULT LoginToServer( LPCSTR szUserName, LPCSTR szPassword );
  80. HRESULT LogoffFromServer( void );
  81. HRESULT FindFile( LPCSTR szRemoteFileName, int * piSize );
  82. HRESULT FileRecoveryPosition( LPCSTR szLocalFileName, LPCSTR szRegistryRoot );
  83. HRESULT RestartFrom( int i ) { m_iFilePos = i; return FTP_SUCCEEDED; };
  84. HRESULT GetNextFileBlock( LPCSTR szLocalFileName, int * piTotalRead );
  85. HRESULT RecvReply( LPCSTR pReplyBuffer, int iSize, int * piRetCode );
  86. HRESULT SendCommand( LPCSTR pCommand, int iSize );
  87. };
  88. #endif //__FTP_H_