Main Page | Namespace List | Class Hierarchy | Class List | Directories | 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.17  2004/11/11 07:34:50  csoutheren
00029  * Added #include <ptlib.h>
00030  *
00031  * Revision 1.16  2003/09/17 05:43:49  csoutheren
00032  * Removed recursive includes
00033  *
00034  * Revision 1.15  2002/11/06 22:47:23  robertj
00035  * Fixed header comment (copyright etc)
00036  *
00037  * Revision 1.14  2002/09/16 01:08:59  robertj
00038  * Added #define so can select if #pragma interface/implementation is used on
00039  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00040  *
00041  * Revision 1.13  2001/09/10 00:28:21  robertj
00042  * Fixed extra CR in comments.
00043  *
00044  * Revision 1.12  2000/06/21 01:01:21  robertj
00045  * AIX port, thanks Wolfgang Platzer (wolfgang.platzer@infonova.at).
00046  *
00047  * Revision 1.11  1999/03/09 08:01:46  robertj
00048  * Changed comments for doc++ support (more to come).
00049  *
00050  * Revision 1.10  1999/02/16 08:07:10  robertj
00051  * MSVC 6.0 compatibility changes.
00052  *
00053  * Revision 1.9  1998/11/30 02:50:45  robertj
00054  * New directory structure
00055  *
00056  * Revision 1.8  1998/09/23 06:19:26  robertj
00057  * Added open source copyright license.
00058  *
00059  * Revision 1.7  1996/10/26 01:39:41  robertj
00060  * Added check for security breach using 3 way FTP transfer or use of privileged PORT.
00061  *
00062  * Revision 1.6  1996/09/14 13:09:08  robertj
00063  * Major upgrade:
00064  *   rearranged sockets to help support IPX.
00065  *   added indirect channel class and moved all protocols to descend from it,
00066  *   separating the protocol from the low level byte transport.
00067  *
00068  * Revision 1.5  1996/05/23 09:56:24  robertj
00069  * Changed FTP so can do passive/active mode on all data transfers.
00070  *
00071  * Revision 1.4  1996/03/31 08:45:57  robertj
00072  * Added QUIT command sent on FTP socket close.
00073  *
00074  * Revision 1.3  1996/03/26 00:50:28  robertj
00075  * FTP Client Implementation.
00076  *
00077  * Revision 1.2  1996/03/18 13:33:10  robertj
00078  * Fixed incompatibilities to GNU compiler where PINDEX != int.
00079  *
00080  * Revision 1.1  1996/03/04 12:14:18  robertj
00081  * Initial revision
00082  *
00083  */
00084 
00085 #ifndef _PFTPSOCKET
00086 #define _PFTPSOCKET
00087 
00088 #ifdef P_USE_PRAGMA
00089 #pragma interface
00090 #endif
00091 
00092 #include <ptclib/inetprot.h>
00093 #include <ptlib/sockets.h>
00094 
00095 
00099 class PFTP : public PInternetProtocol
00100 {
00101   PCLASSINFO(PFTP, PInternetProtocol);
00102   public:
00104     enum Commands { 
00105       USER, PASS, ACCT, CWD, CDUP, SMNT, QUIT, REIN, PORT, PASV, TYPE,
00106       STRU, MODE, RETR, STOR, STOU, APPE, ALLO, REST, RNFR, RNTO, ABOR,
00107       DELE, RMD, MKD, PWD, LIST, NLST, SITE, SYST, STATcmd, HELP, NOOP,
00108       NumCommands
00109     };
00110 
00112     enum RepresentationType {
00113       ASCII,
00114       EBCDIC,
00115       Image
00116     };
00117 
00119     enum DataChannelType {
00120       NormalPort,
00121       Passive
00122     };
00123 
00125     enum NameTypes {
00126       ShortNames,
00127       DetailedNames
00128     };
00129 
00133     BOOL SendPORT(
00134       const PIPSocket::Address & addr,
00137       WORD port 
00138     );
00139 
00140 
00141   protected:
00143     PFTP();
00144 };
00145 
00146 
00150 class PFTPClient : public PFTP
00151 {
00152   PCLASSINFO(PFTPClient, PFTP);
00153   public:
00155     PFTPClient();
00156 
00158     ~PFTPClient();
00159 
00160 
00168     virtual BOOL Close();
00169 
00171 
00179     BOOL LogIn(
00180       const PString & username,   
00181       const PString & password    
00182     );
00183 
00189     PString GetSystemType();
00190 
00196     BOOL SetType(
00197       RepresentationType type   
00198     );
00199 
00205     BOOL ChangeDirectory(
00206       const PString & dirPath     
00207     );
00208 
00214     PString GetCurrentDirectory();
00215 
00222     PStringArray GetDirectoryNames(
00223       NameTypes type = ShortNames,        
00224       DataChannelType channel = Passive   
00225     );
00232     PStringArray GetDirectoryNames(
00233       const PString & path,               
00234       NameTypes type = ShortNames,        
00235       DataChannelType channel = Passive   
00236     );
00237 
00243     PString GetFileStatus(
00244       const PString & path,                
00245       DataChannelType channel = Passive    
00246     );
00247 
00256     PTCPSocket * GetFile(
00257       const PString & filename,            
00258       DataChannelType channel = NormalPort 
00259     );
00260 
00269     PTCPSocket * PutFile(
00270       const PString & filename,   
00271       DataChannelType channel = NormalPort 
00272     );
00273 
00275 
00276   protected:
00278     virtual BOOL OnOpen();
00279 
00280     PTCPSocket * NormalClientTransfer(
00281       Commands cmd,
00282       const PString & args
00283     );
00284     PTCPSocket * PassiveClientTransfer(
00285       Commands cmd,
00286       const PString & args
00287     );
00288 
00290     WORD remotePort;
00291 };
00292 
00293 
00297 class PFTPServer : public PFTP
00298 {
00299   PCLASSINFO(PFTPServer, PFTP);
00300   public:
00301     enum { MaxIllegalPasswords = 3 };
00302 
00304     PFTPServer();
00305     PFTPServer(
00306       const PString & readyString   
00307     );
00308 
00310     ~PFTPServer();
00311 
00312 
00313   // New functions for class
00318     virtual PString GetHelloString(const PString & user) const;
00319 
00321     virtual PString GetGoodbyeString(const PString & user) const;
00322 
00324     virtual PString GetSystemTypeString() const;
00325 
00327     BOOL GetAllowThirdPartyPort() const { return thirdPartyPort; }
00328 
00330     void SetAllowThirdPartyPort(BOOL state) { thirdPartyPort = state; }
00331 
00339     BOOL ProcessCommand();
00340 
00348     virtual BOOL DispatchCommand(
00349       PINDEX code,          
00350       const PString & args  
00351     );
00352 
00353 
00360     virtual BOOL CheckLoginRequired(
00361       PINDEX cmd    
00362     );
00363 
00372     virtual BOOL AuthoriseUser(
00373       const PString & user,     
00374       const PString & password, 
00375       BOOL & replied            
00376     );
00377 
00384     virtual BOOL OnUnknown(
00385       const PCaselessString & command  
00386     );
00387 
00394     virtual void OnError(
00395       PINDEX errorCode, 
00396       PINDEX cmdNum,    
00397       const char * msg  
00398     );
00399 
00401     virtual void OnSyntaxError(
00402       PINDEX cmdNum   
00403     );
00404 
00406     virtual void OnNotImplemented(
00407       PINDEX cmdNum   
00408     );
00409 
00411     virtual void OnCommandSuccessful(
00412       PINDEX cmdNum   
00413     );
00414 
00415 
00416     // the following commands must be implemented by all servers
00417     // and can be performed without logging in
00418     virtual BOOL OnUSER(const PCaselessString & args);
00419     virtual BOOL OnPASS(const PCaselessString & args);  // officially optional, but should be done
00420     virtual BOOL OnQUIT(const PCaselessString & args);
00421     virtual BOOL OnPORT(const PCaselessString & args);
00422     virtual BOOL OnSTRU(const PCaselessString & args);
00423     virtual BOOL OnMODE(const PCaselessString & args);
00424     virtual BOOL OnTYPE(const PCaselessString & args);
00425     virtual BOOL OnNOOP(const PCaselessString & args);
00426     virtual BOOL OnSYST(const PCaselessString & args);
00427     virtual BOOL OnSTAT(const PCaselessString & args);
00428 
00429     // the following commands must be implemented by all servers
00430     // and cannot be performed without logging in
00431     virtual BOOL OnRETR(const PCaselessString & args);
00432     virtual BOOL OnSTOR(const PCaselessString & args);
00433     virtual BOOL OnACCT(const PCaselessString & args);
00434     virtual BOOL OnAPPE(const PCaselessString & args);
00435     virtual BOOL OnRNFR(const PCaselessString & args);
00436     virtual BOOL OnRNTO(const PCaselessString & args);
00437     virtual BOOL OnDELE(const PCaselessString & args);
00438     virtual BOOL OnCWD(const PCaselessString & args);
00439     virtual BOOL OnCDUP(const PCaselessString & args);
00440     virtual BOOL OnRMD(const PCaselessString & args);
00441     virtual BOOL OnMKD(const PCaselessString & args);
00442     virtual BOOL OnPWD(const PCaselessString & args);
00443     virtual BOOL OnLIST(const PCaselessString & args);
00444     virtual BOOL OnNLST(const PCaselessString & args);
00445     virtual BOOL OnPASV(const PCaselessString & args);
00446 
00447     // the following commands are optional and can be performed without
00448     // logging in
00449     virtual BOOL OnHELP(const PCaselessString & args);
00450     virtual BOOL OnSITE(const PCaselessString & args);
00451     virtual BOOL OnABOR(const PCaselessString & args);
00452 
00453     // the following commands are optional and cannot be performed
00454     // without logging in
00455     virtual BOOL OnSMNT(const PCaselessString & args);
00456     virtual BOOL OnREIN(const PCaselessString & args);
00457     virtual BOOL OnSTOU(const PCaselessString & args);
00458     virtual BOOL OnALLO(const PCaselessString & args);
00459     virtual BOOL OnREST(const PCaselessString & args);
00460 
00461 
00463     void SendToClient(
00464       const PFilePath & filename    
00465     );
00466 
00467 
00468   protected:
00470     BOOL OnOpen();
00471     void Construct();
00472 
00473     PString readyString;
00474     BOOL    thirdPartyPort;
00475 
00476     enum {
00477       NotConnected,
00478       NeedUser,
00479       NeedPassword,
00480       Connected,
00481       ClientConnect
00482     } state;
00483 
00484     PIPSocket::Address remoteHost;
00485     WORD remotePort;
00486 
00487     PTCPSocket * passiveSocket;
00488 
00489     char    type;
00490     char    structure;
00491     char    mode;
00492     PString userName;
00493     int     illegalPasswordCount;
00494 };
00495 
00496 
00497 #endif
00498 
00499 
00500 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 21 20:43:08 2005 for PWLib by  doxygen 1.4.1