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  * $Revision: 20385 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00030  */
00031 
00032 #ifndef _PFTPSOCKET
00033 #define _PFTPSOCKET
00034 
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038 
00039 #include <ptclib/inetprot.h>
00040 #include <ptlib/sockets.h>
00041 
00042 
00046 class PFTP : public PInternetProtocol
00047 {
00048   PCLASSINFO(PFTP, PInternetProtocol);
00049   public:
00051     enum Commands { 
00052       USER, PASS, ACCT, CWD, CDUP, SMNT, QUIT, REIN, PORT, PASV, TYPE,
00053       STRU, MODE, RETR, STOR, STOU, APPE, ALLO, REST, RNFR, RNTO, ABOR,
00054       DELE, RMD, MKD, PWD, LIST, NLST, SITE, SYST, STATcmd, HELP, NOOP,
00055       NumCommands
00056     };
00057 
00059     enum RepresentationType {
00060       ASCII,
00061       EBCDIC,
00062       Image
00063     };
00064 
00066     enum DataChannelType {
00067       NormalPort,
00068       Passive
00069     };
00070 
00072     enum NameTypes {
00073       ShortNames,
00074       DetailedNames
00075     };
00076 
00080     PBoolean SendPORT(
00081       const PIPSocket::Address & addr, 
00082       WORD port                        
00083     );
00084 
00085 
00086   protected:
00088     PFTP();
00089 };
00090 
00091 
00095 class PFTPClient : public PFTP
00096 {
00097   PCLASSINFO(PFTPClient, PFTP);
00098   public:
00100     PFTPClient();
00101 
00103     ~PFTPClient();
00104 
00105 
00113     virtual PBoolean Close();
00114 
00116 
00124     PBoolean LogIn(
00125       const PString & username,   
00126       const PString & password    
00127     );
00128 
00134     PString GetSystemType();
00135 
00141     PBoolean SetType(
00142       RepresentationType type   
00143     );
00144 
00150     PBoolean ChangeDirectory(
00151       const PString & dirPath     
00152     );
00153 
00159     PString GetCurrentDirectory();
00160 
00167     PStringArray GetDirectoryNames(
00168       NameTypes type = ShortNames,        
00169       DataChannelType channel = Passive   
00170     );
00177     PStringArray GetDirectoryNames(
00178       const PString & path,               
00179       NameTypes type = ShortNames,        
00180       DataChannelType channel = Passive   
00181     );
00182 
00188     PString GetFileStatus(
00189       const PString & path,                
00190       DataChannelType channel = Passive    
00191     );
00192 
00201     PTCPSocket * GetFile(
00202       const PString & filename,            
00203       DataChannelType channel = NormalPort 
00204     );
00205 
00214     PTCPSocket * PutFile(
00215       const PString & filename,   
00216       DataChannelType channel = NormalPort 
00217     );
00218 
00220 
00221   protected:
00223     virtual PBoolean OnOpen();
00224 
00225     PTCPSocket * NormalClientTransfer(
00226       Commands cmd,
00227       const PString & args
00228     );
00229     PTCPSocket * PassiveClientTransfer(
00230       Commands cmd,
00231       const PString & args
00232     );
00233 
00235     WORD remotePort;
00236 };
00237 
00238 
00242 class PFTPServer : public PFTP
00243 {
00244   PCLASSINFO(PFTPServer, PFTP);
00245   public:
00246     enum { MaxIllegalPasswords = 3 };
00247 
00249     PFTPServer();
00250     PFTPServer(
00251       const PString & readyString   
00252     );
00253 
00255     ~PFTPServer();
00256 
00257 
00258   // New functions for class
00263     virtual PString GetHelloString(const PString & user) const;
00264 
00266     virtual PString GetGoodbyeString(const PString & user) const;
00267 
00269     virtual PString GetSystemTypeString() const;
00270 
00272     PBoolean GetAllowThirdPartyPort() const { return thirdPartyPort; }
00273 
00275     void SetAllowThirdPartyPort(PBoolean state) { thirdPartyPort = state; }
00276 
00284     PBoolean ProcessCommand();
00285 
00293     virtual PBoolean DispatchCommand(
00294       PINDEX code,          
00295       const PString & args  
00296     );
00297 
00298 
00305     virtual PBoolean CheckLoginRequired(
00306       PINDEX cmd    
00307     );
00308 
00317     virtual PBoolean AuthoriseUser(
00318       const PString & user,     
00319       const PString & password, 
00320       PBoolean & replied            
00321     );
00322 
00329     virtual PBoolean OnUnknown(
00330       const PCaselessString & command  
00331     );
00332 
00339     virtual void OnError(
00340       PINDEX errorCode, 
00341       PINDEX cmdNum,    
00342       const char * msg  
00343     );
00344 
00346     virtual void OnSyntaxError(
00347       PINDEX cmdNum   
00348     );
00349 
00351     virtual void OnNotImplemented(
00352       PINDEX cmdNum   
00353     );
00354 
00356     virtual void OnCommandSuccessful(
00357       PINDEX cmdNum   
00358     );
00359 
00360 
00361     // the following commands must be implemented by all servers
00362     // and can be performed without logging in
00363     virtual PBoolean OnUSER(const PCaselessString & args);
00364     virtual PBoolean OnPASS(const PCaselessString & args);  // officially optional, but should be done
00365     virtual PBoolean OnQUIT(const PCaselessString & args);
00366     virtual PBoolean OnPORT(const PCaselessString & args);
00367     virtual PBoolean OnSTRU(const PCaselessString & args);
00368     virtual PBoolean OnMODE(const PCaselessString & args);
00369     virtual PBoolean OnTYPE(const PCaselessString & args);
00370     virtual PBoolean OnNOOP(const PCaselessString & args);
00371     virtual PBoolean OnSYST(const PCaselessString & args);
00372     virtual PBoolean OnSTAT(const PCaselessString & args);
00373 
00374     // the following commands must be implemented by all servers
00375     // and cannot be performed without logging in
00376     virtual PBoolean OnRETR(const PCaselessString & args);
00377     virtual PBoolean OnSTOR(const PCaselessString & args);
00378     virtual PBoolean OnACCT(const PCaselessString & args);
00379     virtual PBoolean OnAPPE(const PCaselessString & args);
00380     virtual PBoolean OnRNFR(const PCaselessString & args);
00381     virtual PBoolean OnRNTO(const PCaselessString & args);
00382     virtual PBoolean OnDELE(const PCaselessString & args);
00383     virtual PBoolean OnCWD(const PCaselessString & args);
00384     virtual PBoolean OnCDUP(const PCaselessString & args);
00385     virtual PBoolean OnRMD(const PCaselessString & args);
00386     virtual PBoolean OnMKD(const PCaselessString & args);
00387     virtual PBoolean OnPWD(const PCaselessString & args);
00388     virtual PBoolean OnLIST(const PCaselessString & args);
00389     virtual PBoolean OnNLST(const PCaselessString & args);
00390     virtual PBoolean OnPASV(const PCaselessString & args);
00391 
00392     // the following commands are optional and can be performed without
00393     // logging in
00394     virtual PBoolean OnHELP(const PCaselessString & args);
00395     virtual PBoolean OnSITE(const PCaselessString & args);
00396     virtual PBoolean OnABOR(const PCaselessString & args);
00397 
00398     // the following commands are optional and cannot be performed
00399     // without logging in
00400     virtual PBoolean OnSMNT(const PCaselessString & args);
00401     virtual PBoolean OnREIN(const PCaselessString & args);
00402     virtual PBoolean OnSTOU(const PCaselessString & args);
00403     virtual PBoolean OnALLO(const PCaselessString & args);
00404     virtual PBoolean OnREST(const PCaselessString & args);
00405 
00406 
00408     void SendToClient(
00409       const PFilePath & filename    
00410     );
00411 
00412 
00413   protected:
00415     PBoolean OnOpen();
00416     void Construct();
00417 
00418     PString readyString;
00419     PBoolean    thirdPartyPort;
00420 
00421     enum {
00422       NotConnected,
00423       NeedUser,
00424       NeedPassword,
00425       Connected,
00426       ClientConnect
00427     } state;
00428 
00429     PIPSocket::Address remoteHost;
00430     WORD remotePort;
00431 
00432     PTCPSocket * passiveSocket;
00433 
00434     char    type;
00435     char    structure;
00436     char    mode;
00437     PString userName;
00438     int     illegalPasswordCount;
00439 };
00440 
00441 
00442 #endif
00443 
00444 
00445 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1