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: 21788 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-12-11 23:42:13 -0600 (Thu, 11 Dec 2008) $
00030  */
00031 
00032 #ifndef PTLIB_FTP_H
00033 #define PTLIB_FTP_H
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     PBoolean CreateDirectory(
00189       const PString & path                
00190     );
00191 
00197     PString GetFileStatus(
00198       const PString & path,                
00199       DataChannelType channel = Passive    
00200     );
00201 
00210     PTCPSocket * GetFile(
00211       const PString & filename,            
00212       DataChannelType channel = NormalPort 
00213     );
00214 
00223     PTCPSocket * PutFile(
00224       const PString & filename,   
00225       DataChannelType channel = NormalPort 
00226     );
00227 
00229 
00230   protected:
00232     virtual PBoolean OnOpen();
00233 
00234     PTCPSocket * NormalClientTransfer(
00235       Commands cmd,
00236       const PString & args
00237     );
00238     PTCPSocket * PassiveClientTransfer(
00239       Commands cmd,
00240       const PString & args
00241     );
00242 
00244     WORD remotePort;
00245 };
00246 
00247 
00251 class PFTPServer : public PFTP
00252 {
00253   PCLASSINFO(PFTPServer, PFTP);
00254   public:
00255     enum { MaxIllegalPasswords = 3 };
00256 
00258     PFTPServer();
00259     PFTPServer(
00260       const PString & readyString   
00261     );
00262 
00264     ~PFTPServer();
00265 
00266 
00267   // New functions for class
00272     virtual PString GetHelloString(const PString & user) const;
00273 
00275     virtual PString GetGoodbyeString(const PString & user) const;
00276 
00278     virtual PString GetSystemTypeString() const;
00279 
00281     PBoolean GetAllowThirdPartyPort() const { return thirdPartyPort; }
00282 
00284     void SetAllowThirdPartyPort(PBoolean state) { thirdPartyPort = state; }
00285 
00293     PBoolean ProcessCommand();
00294 
00302     virtual PBoolean DispatchCommand(
00303       PINDEX code,          
00304       const PString & args  
00305     );
00306 
00307 
00314     virtual PBoolean CheckLoginRequired(
00315       PINDEX cmd    
00316     );
00317 
00326     virtual PBoolean AuthoriseUser(
00327       const PString & user,     
00328       const PString & password, 
00329       PBoolean & replied            
00330     );
00331 
00338     virtual PBoolean OnUnknown(
00339       const PCaselessString & command  
00340     );
00341 
00348     virtual void OnError(
00349       PINDEX errorCode, 
00350       PINDEX cmdNum,    
00351       const char * msg  
00352     );
00353 
00355     virtual void OnSyntaxError(
00356       PINDEX cmdNum   
00357     );
00358 
00360     virtual void OnNotImplemented(
00361       PINDEX cmdNum   
00362     );
00363 
00365     virtual void OnCommandSuccessful(
00366       PINDEX cmdNum   
00367     );
00368 
00369 
00370     // the following commands must be implemented by all servers
00371     // and can be performed without logging in
00372     virtual PBoolean OnUSER(const PCaselessString & args);
00373     virtual PBoolean OnPASS(const PCaselessString & args);  // officially optional, but should be done
00374     virtual PBoolean OnQUIT(const PCaselessString & args);
00375     virtual PBoolean OnPORT(const PCaselessString & args);
00376     virtual PBoolean OnSTRU(const PCaselessString & args);
00377     virtual PBoolean OnMODE(const PCaselessString & args);
00378     virtual PBoolean OnTYPE(const PCaselessString & args);
00379     virtual PBoolean OnNOOP(const PCaselessString & args);
00380     virtual PBoolean OnSYST(const PCaselessString & args);
00381     virtual PBoolean OnSTAT(const PCaselessString & args);
00382 
00383     // the following commands must be implemented by all servers
00384     // and cannot be performed without logging in
00385     virtual PBoolean OnRETR(const PCaselessString & args);
00386     virtual PBoolean OnSTOR(const PCaselessString & args);
00387     virtual PBoolean OnACCT(const PCaselessString & args);
00388     virtual PBoolean OnAPPE(const PCaselessString & args);
00389     virtual PBoolean OnRNFR(const PCaselessString & args);
00390     virtual PBoolean OnRNTO(const PCaselessString & args);
00391     virtual PBoolean OnDELE(const PCaselessString & args);
00392     virtual PBoolean OnCWD(const PCaselessString & args);
00393     virtual PBoolean OnCDUP(const PCaselessString & args);
00394     virtual PBoolean OnRMD(const PCaselessString & args);
00395     virtual PBoolean OnMKD(const PCaselessString & args);
00396     virtual PBoolean OnPWD(const PCaselessString & args);
00397     virtual PBoolean OnLIST(const PCaselessString & args);
00398     virtual PBoolean OnNLST(const PCaselessString & args);
00399     virtual PBoolean OnPASV(const PCaselessString & args);
00400 
00401     // the following commands are optional and can be performed without
00402     // logging in
00403     virtual PBoolean OnHELP(const PCaselessString & args);
00404     virtual PBoolean OnSITE(const PCaselessString & args);
00405     virtual PBoolean OnABOR(const PCaselessString & args);
00406 
00407     // the following commands are optional and cannot be performed
00408     // without logging in
00409     virtual PBoolean OnSMNT(const PCaselessString & args);
00410     virtual PBoolean OnREIN(const PCaselessString & args);
00411     virtual PBoolean OnSTOU(const PCaselessString & args);
00412     virtual PBoolean OnALLO(const PCaselessString & args);
00413     virtual PBoolean OnREST(const PCaselessString & args);
00414 
00415 
00417     void SendToClient(
00418       const PFilePath & filename    
00419     );
00420 
00421 
00422   protected:
00424     PBoolean OnOpen();
00425     void Construct();
00426 
00427     PString readyString;
00428     PBoolean    thirdPartyPort;
00429 
00430     enum {
00431       NotConnected,
00432       NeedUser,
00433       NeedPassword,
00434       Connected,
00435       ClientConnect
00436     } state;
00437 
00438     PIPSocket::Address remoteHost;
00439     WORD remotePort;
00440 
00441     PTCPSocket * passiveSocket;
00442 
00443     char    type;
00444     char    structure;
00445     char    mode;
00446     PString userName;
00447     int     illegalPasswordCount;
00448 };
00449 
00450 
00451 #endif // PTLIB_FTP_H
00452 
00453 
00454 // End of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:36:47 2010 for PTLib by  doxygen 1.4.7