Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

ftp.h

Go to the documentation of this file.
00001 /* 00002 * ftp.h 00003 * 00004 * File Transfer Protocol Server/Client channel classes 00005 * As per RFC 959 and RFC 1123 00006 * 00007 * Portable Windows Library 00008 * 00009 * Copyright (c) 1993-2002 Equivalence Pty. Ltd. 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Portable Windows Library. 00022 * 00023 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00024 * 00025 * Contributor(s): ______________________________________. 00026 * 00027 * $Log: ftp.h,v $ 00028 * Revision 1.16 2003/09/17 05:43:49 csoutheren 00029 * Removed recursive includes 00030 * 00031 * Revision 1.15 2002/11/06 22:47:23 robertj 00032 * Fixed header comment (copyright etc) 00033 * 00034 * Revision 1.14 2002/09/16 01:08:59 robertj 00035 * Added #define so can select if #pragma interface/implementation is used on 00036 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00037 * 00038 * Revision 1.13 2001/09/10 00:28:21 robertj 00039 * Fixed extra CR in comments. 00040 * 00041 * Revision 1.12 2000/06/21 01:01:21 robertj 00042 * AIX port, thanks Wolfgang Platzer (wolfgang.platzer@infonova.at). 00043 * 00044 * Revision 1.11 1999/03/09 08:01:46 robertj 00045 * Changed comments for doc++ support (more to come). 00046 * 00047 * Revision 1.10 1999/02/16 08:07:10 robertj 00048 * MSVC 6.0 compatibility changes. 00049 * 00050 * Revision 1.9 1998/11/30 02:50:45 robertj 00051 * New directory structure 00052 * 00053 * Revision 1.8 1998/09/23 06:19:26 robertj 00054 * Added open source copyright license. 00055 * 00056 * Revision 1.7 1996/10/26 01:39:41 robertj 00057 * Added check for security breach using 3 way FTP transfer or use of privileged PORT. 00058 * 00059 * Revision 1.6 1996/09/14 13:09:08 robertj 00060 * Major upgrade: 00061 * rearranged sockets to help support IPX. 00062 * added indirect channel class and moved all protocols to descend from it, 00063 * separating the protocol from the low level byte transport. 00064 * 00065 * Revision 1.5 1996/05/23 09:56:24 robertj 00066 * Changed FTP so can do passive/active mode on all data transfers. 00067 * 00068 * Revision 1.4 1996/03/31 08:45:57 robertj 00069 * Added QUIT command sent on FTP socket close. 00070 * 00071 * Revision 1.3 1996/03/26 00:50:28 robertj 00072 * FTP Client Implementation. 00073 * 00074 * Revision 1.2 1996/03/18 13:33:10 robertj 00075 * Fixed incompatibilities to GNU compiler where PINDEX != int. 00076 * 00077 * Revision 1.1 1996/03/04 12:14:18 robertj 00078 * Initial revision 00079 * 00080 */ 00081 00082 #ifndef _PFTPSOCKET 00083 #define _PFTPSOCKET 00084 00085 #ifdef P_USE_PRAGMA 00086 #pragma interface 00087 #endif 00088 00089 #include <ptclib/inetprot.h> 00090 #include "ptlib/sockets.h" 00091 00092 00096 class PFTP : public PInternetProtocol 00097 { 00098 PCLASSINFO(PFTP, PInternetProtocol); 00099 public: 00101 enum Commands { 00102 USER, PASS, ACCT, CWD, CDUP, SMNT, QUIT, REIN, PORT, PASV, TYPE, 00103 STRU, MODE, RETR, STOR, STOU, APPE, ALLO, REST, RNFR, RNTO, ABOR, 00104 DELE, RMD, MKD, PWD, LIST, NLST, SITE, SYST, STATcmd, HELP, NOOP, 00105 NumCommands 00106 }; 00107 00109 enum RepresentationType { 00110 ASCII, 00111 EBCDIC, 00112 Image 00113 }; 00114 00116 enum DataChannelType { 00117 NormalPort, 00118 Passive 00119 }; 00120 00122 enum NameTypes { 00123 ShortNames, 00124 DetailedNames 00125 }; 00126 00130 BOOL SendPORT( 00131 const PIPSocket::Address & addr, 00134 WORD port 00135 ); 00136 00137 00138 protected: 00140 PFTP(); 00141 }; 00142 00143 00147 class PFTPClient : public PFTP 00148 { 00149 PCLASSINFO(PFTPClient, PFTP); 00150 public: 00152 PFTPClient(); 00153 00155 ~PFTPClient(); 00156 00157 00165 virtual BOOL Close(); 00166 00168 00176 BOOL LogIn( 00177 const PString & username, 00178 const PString & password 00179 ); 00180 00186 PString GetSystemType(); 00187 00193 BOOL SetType( 00194 RepresentationType type 00195 ); 00196 00202 BOOL ChangeDirectory( 00203 const PString & dirPath 00204 ); 00205 00211 PString GetCurrentDirectory(); 00212 00219 PStringArray GetDirectoryNames( 00220 NameTypes type = ShortNames, 00221 DataChannelType channel = Passive 00222 ); 00229 PStringArray GetDirectoryNames( 00230 const PString & path, 00231 NameTypes type = ShortNames, 00232 DataChannelType channel = Passive 00233 ); 00234 00240 PString GetFileStatus( 00241 const PString & path, 00242 DataChannelType channel = Passive 00243 ); 00244 00253 PTCPSocket * GetFile( 00254 const PString & filename, 00255 DataChannelType channel = NormalPort 00256 ); 00257 00266 PTCPSocket * PutFile( 00267 const PString & filename, 00268 DataChannelType channel = NormalPort 00269 ); 00270 00272 00273 protected: 00275 virtual BOOL OnOpen(); 00276 00277 PTCPSocket * NormalClientTransfer( 00278 Commands cmd, 00279 const PString & args 00280 ); 00281 PTCPSocket * PassiveClientTransfer( 00282 Commands cmd, 00283 const PString & args 00284 ); 00285 00287 WORD remotePort; 00288 }; 00289 00290 00294 class PFTPServer : public PFTP 00295 { 00296 PCLASSINFO(PFTPServer, PFTP); 00297 public: 00298 enum { MaxIllegalPasswords = 3 }; 00299 00301 PFTPServer(); 00302 PFTPServer( 00303 const PString & readyString 00304 ); 00305 00307 ~PFTPServer(); 00308 00309 00310 // New functions for class 00315 virtual PString GetHelloString(const PString & user) const; 00316 00318 virtual PString GetGoodbyeString(const PString & user) const; 00319 00321 virtual PString GetSystemTypeString() const; 00322 00324 BOOL GetAllowThirdPartyPort() const { return thirdPartyPort; } 00325 00327 void SetAllowThirdPartyPort(BOOL state) { thirdPartyPort = state; } 00328 00336 BOOL ProcessCommand(); 00337 00345 virtual BOOL DispatchCommand( 00346 PINDEX code, 00347 const PString & args 00348 ); 00349 00350 00357 virtual BOOL CheckLoginRequired( 00358 PINDEX cmd 00359 ); 00360 00369 virtual BOOL AuthoriseUser( 00370 const PString & user, 00371 const PString & password, 00372 BOOL & replied 00373 ); 00374 00381 virtual BOOL OnUnknown( 00382 const PCaselessString & command 00383 ); 00384 00391 virtual void OnError( 00392 PINDEX errorCode, 00393 PINDEX cmdNum, 00394 const char * msg 00395 ); 00396 00398 virtual void OnSyntaxError( 00399 PINDEX cmdNum 00400 ); 00401 00403 virtual void OnNotImplemented( 00404 PINDEX cmdNum 00405 ); 00406 00408 virtual void OnCommandSuccessful( 00409 PINDEX cmdNum 00410 ); 00411 00412 00413 // the following commands must be implemented by all servers 00414 // and can be performed without logging in 00415 virtual BOOL OnUSER(const PCaselessString & args); 00416 virtual BOOL OnPASS(const PCaselessString & args); // officially optional, but should be done 00417 virtual BOOL OnQUIT(const PCaselessString & args); 00418 virtual BOOL OnPORT(const PCaselessString & args); 00419 virtual BOOL OnSTRU(const PCaselessString & args); 00420 virtual BOOL OnMODE(const PCaselessString & args); 00421 virtual BOOL OnTYPE(const PCaselessString & args); 00422 virtual BOOL OnNOOP(const PCaselessString & args); 00423 virtual BOOL OnSYST(const PCaselessString & args); 00424 virtual BOOL OnSTAT(const PCaselessString & args); 00425 00426 // the following commands must be implemented by all servers 00427 // and cannot be performed without logging in 00428 virtual BOOL OnRETR(const PCaselessString & args); 00429 virtual BOOL OnSTOR(const PCaselessString & args); 00430 virtual BOOL OnACCT(const PCaselessString & args); 00431 virtual BOOL OnAPPE(const PCaselessString & args); 00432 virtual BOOL OnRNFR(const PCaselessString & args); 00433 virtual BOOL OnRNTO(const PCaselessString & args); 00434 virtual BOOL OnDELE(const PCaselessString & args); 00435 virtual BOOL OnCWD(const PCaselessString & args); 00436 virtual BOOL OnCDUP(const PCaselessString & args); 00437 virtual BOOL OnRMD(const PCaselessString & args); 00438 virtual BOOL OnMKD(const PCaselessString & args); 00439 virtual BOOL OnPWD(const PCaselessString & args); 00440 virtual BOOL OnLIST(const PCaselessString & args); 00441 virtual BOOL OnNLST(const PCaselessString & args); 00442 virtual BOOL OnPASV(const PCaselessString & args); 00443 00444 // the following commands are optional and can be performed without 00445 // logging in 00446 virtual BOOL OnHELP(const PCaselessString & args); 00447 virtual BOOL OnSITE(const PCaselessString & args); 00448 virtual BOOL OnABOR(const PCaselessString & args); 00449 00450 // the following commands are optional and cannot be performed 00451 // without logging in 00452 virtual BOOL OnSMNT(const PCaselessString & args); 00453 virtual BOOL OnREIN(const PCaselessString & args); 00454 virtual BOOL OnSTOU(const PCaselessString & args); 00455 virtual BOOL OnALLO(const PCaselessString & args); 00456 virtual BOOL OnREST(const PCaselessString & args); 00457 00458 00460 void SendToClient( 00461 const PFilePath & filename 00462 ); 00463 00464 00465 protected: 00467 BOOL OnOpen(); 00468 void Construct(); 00469 00470 PString readyString; 00471 BOOL thirdPartyPort; 00472 00473 enum { 00474 NotConnected, 00475 NeedUser, 00476 NeedPassword, 00477 Connected, 00478 ClientConnect 00479 } state; 00480 00481 PIPSocket::Address remoteHost; 00482 WORD remotePort; 00483 00484 PTCPSocket * passiveSocket; 00485 00486 char type; 00487 char structure; 00488 char mode; 00489 PString userName; 00490 int illegalPasswordCount; 00491 }; 00492 00493 00494 #endif 00495 00496 00497 // End of File ///////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7