PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ftp.h
Go to the documentation of this file.
1 /*
2  * ftp.h
3  *
4  * File Transfer Protocol Server/Client channel classes
5  * As per RFC 959 and RFC 1123
6  *
7  * Portable Windows Library
8  *
9  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Portable Windows Library.
22  *
23  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24  *
25  * Contributor(s): ______________________________________.
26  */
27 
28 #ifndef PTLIB_FTP_H
29 #define PTLIB_FTP_H
30 
31 #ifdef P_USE_PRAGMA
32 #pragma interface
33 #endif
34 
35 #if P_FTP
36 
37 #include <ptclib/inetprot.h>
38 #include <ptlib/sockets.h>
39 
40 
41 class PURL;
42 
43 
47 class PFTP : public PInternetProtocol
48 {
49  PCLASSINFO(PFTP, PInternetProtocol);
50  public:
52  enum Commands {
57  };
58 
64  };
65 
70  };
71 
73  enum NameTypes {
76  };
77 
78  enum {
80  };
81 
86  const PIPSocket::Address & addr,
87  WORD port
88  );
89 
90 
91  protected:
93  PFTP();
94 };
95 
96 
100 class PFTPClient : public PFTP
101 {
102  PCLASSINFO(PFTPClient, PFTP);
103  public:
105  PFTPClient();
106 
108  ~PFTPClient();
109 
110 
118  virtual PBoolean Close();
119 
121 
126  bool OpenHost(
127  const PString & host,
128  WORD port = DefaultPort
129  );
130 
136  PBoolean LogIn(
137  const PString & username,
138  const PString & password
139  );
140 
147 
154  RepresentationType type
155  );
156 
163  const PString & dirPath
164  );
165 
172 
180  NameTypes type = ShortNames,
181  DataChannelType channel = Passive
182  );
190  const PString & path,
191  NameTypes type = ShortNames,
192  DataChannelType channel = Passive
193  );
194 
201  const PString & path
202  );
203 
210  const PString & path,
211  DataChannelType channel = Passive
212  );
213 
223  const PString & filename,
224  DataChannelType channel = Passive
225  );
226 
236  const PString & filename,
237  DataChannelType channel = Passive
238  );
239 
248  PTCPSocket * GetURL(
249  const PURL & url,
250  RepresentationType type,
251  DataChannelType channel = Passive
252  );
253 
255 
256  protected:
258  virtual PBoolean OnOpen();
259 
261  Commands cmd,
262  const PString & args
263  );
265  Commands cmd,
266  const PString & args
267  );
268 
271 };
272 
273 
277 class PFTPServer : public PFTP
278 {
279  PCLASSINFO(PFTPServer, PFTP);
280  public:
281  enum { MaxIllegalPasswords = 3 };
282 
284  PFTPServer();
285  PFTPServer(
286  const PString & readyString
287  );
288 
290  ~PFTPServer();
291 
292 
293  // New functions for class
298  virtual PString GetHelloString(const PString & user) const;
299 
301  virtual PString GetGoodbyeString(const PString & user) const;
302 
304  virtual PString GetSystemTypeString() const;
305 
308 
311 
320 
328  virtual PBoolean DispatchCommand(
329  PINDEX code,
330  const PString & args
331  );
332 
333 
341  PINDEX cmd
342  );
343 
352  virtual PBoolean AuthoriseUser(
353  const PString & user,
354  const PString & password,
355  PBoolean & replied
356  );
357 
364  virtual PBoolean OnUnknown(
365  const PCaselessString & command
366  );
367 
374  virtual void OnError(
375  PINDEX errorCode,
376  PINDEX cmdNum,
377  const char * msg
378  );
379 
381  virtual void OnSyntaxError(
382  PINDEX cmdNum
383  );
384 
386  virtual void OnNotImplemented(
387  PINDEX cmdNum
388  );
389 
391  virtual void OnCommandSuccessful(
392  PINDEX cmdNum
393  );
394 
395 
396  // the following commands must be implemented by all servers
397  // and can be performed without logging in
398  virtual PBoolean OnUSER(const PCaselessString & args);
399  virtual PBoolean OnPASS(const PCaselessString & args); // officially optional, but should be done
400  virtual PBoolean OnQUIT(const PCaselessString & args);
401  virtual PBoolean OnPORT(const PCaselessString & args);
402  virtual PBoolean OnSTRU(const PCaselessString & args);
403  virtual PBoolean OnMODE(const PCaselessString & args);
404  virtual PBoolean OnTYPE(const PCaselessString & args);
405  virtual PBoolean OnNOOP(const PCaselessString & args);
406  virtual PBoolean OnSYST(const PCaselessString & args);
407  virtual PBoolean OnSTAT(const PCaselessString & args);
408 
409  // the following commands must be implemented by all servers
410  // and cannot be performed without logging in
411  virtual PBoolean OnRETR(const PCaselessString & args);
412  virtual PBoolean OnSTOR(const PCaselessString & args);
413  virtual PBoolean OnACCT(const PCaselessString & args);
414  virtual PBoolean OnAPPE(const PCaselessString & args);
415  virtual PBoolean OnRNFR(const PCaselessString & args);
416  virtual PBoolean OnRNTO(const PCaselessString & args);
417  virtual PBoolean OnDELE(const PCaselessString & args);
418  virtual PBoolean OnCWD(const PCaselessString & args);
419  virtual PBoolean OnCDUP(const PCaselessString & args);
420  virtual PBoolean OnRMD(const PCaselessString & args);
421  virtual PBoolean OnMKD(const PCaselessString & args);
422  virtual PBoolean OnPWD(const PCaselessString & args);
423  virtual PBoolean OnLIST(const PCaselessString & args);
424  virtual PBoolean OnNLST(const PCaselessString & args);
425  virtual PBoolean OnPASV(const PCaselessString & args);
426 
427  // the following commands are optional and can be performed without
428  // logging in
429  virtual PBoolean OnHELP(const PCaselessString & args);
430  virtual PBoolean OnSITE(const PCaselessString & args);
431  virtual PBoolean OnABOR(const PCaselessString & args);
432 
433  // the following commands are optional and cannot be performed
434  // without logging in
435  virtual PBoolean OnSMNT(const PCaselessString & args);
436  virtual PBoolean OnREIN(const PCaselessString & args);
437  virtual PBoolean OnSTOU(const PCaselessString & args);
438  virtual PBoolean OnALLO(const PCaselessString & args);
439  virtual PBoolean OnREST(const PCaselessString & args);
440 
441 
443  void SendToClient(
444  const PFilePath & filename
445  );
446 
447 
448  protected:
450  PBoolean OnOpen();
451  void Construct();
452 
455 
456  enum {
462  } m_state;
463 
466 
468 
469  char m_type;
471  char m_mode;
474 };
475 
476 
477 #endif // P_FTP
478 
479 #endif // PTLIB_FTP_H
480 
481 
482 // End of File ///////////////////////////////////////////////////////////////
Definition: ftp.h:55
void SetAllowThirdPartyPort(PBoolean state)
Set the thirdPartyPort flag.
Definition: ftp.h:310
virtual PBoolean OnSITE(const PCaselessString &args)
virtual PBoolean OnHELP(const PCaselessString &args)
Definition: ftp.h:55
PTCPSocket * NormalClientTransfer(Commands cmd, const PString &args)
virtual PBoolean OnPASV(const PCaselessString &args)
Definition: ftp.h:53
virtual PString GetSystemTypeString() const
return the string to be returned by the SYST command
virtual PBoolean OnRNFR(const PCaselessString &args)
PTCPSocket * m_passiveSocket
Definition: ftp.h:467
WORD remotePort
Port number on remote system.
Definition: ftp.h:270
Definition: ftp.h:68
Definition: ftp.h:54
PBoolean SetType(RepresentationType type)
Set the transfer type.
~PFTPClient()
Delete and close the socket.
char m_structure
Definition: ftp.h:470
Definition: ftp.h:55
Definition: ftp.h:74
virtual PBoolean OnCWD(const PCaselessString &args)
virtual PBoolean OnUSER(const PCaselessString &args)
Definition: ftp.h:61
virtual void OnNotImplemented(PINDEX cmdNum)
Called for unimplemented commands.
File Transfer Protocol client channel class.
Definition: ftp.h:100
~PFTPServer()
Delete the server, cleaning up passive sockets.
Definition: ftp.h:54
PFTP()
Construct an ineternal File Transfer Protocol channel.
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
Definition: ftp.h:55
virtual PBoolean OnCDUP(const PCaselessString &args)
virtual PBoolean OnNOOP(const PCaselessString &args)
Definition: ftp.h:54
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
Definition: ftp.h:460
virtual PBoolean CheckLoginRequired(PINDEX cmd)
Check to see if the command requires the server to be logged in before it may be processed.
virtual PBoolean OnTYPE(const PCaselessString &args)
Definition: ftp.h:55
Definition: ftp.h:461
NameTypes
Listing types.
Definition: ftp.h:73
virtual PBoolean OnNLST(const PCaselessString &args)
PString GetFileStatus(const PString &path, DataChannelType channel=Passive)
Get status information for the file path specified.
This is an array collection class of PString objects.
Definition: pstring.h:2365
virtual PBoolean OnALLO(const PCaselessString &args)
File Transfer Protocol server channel class.
Definition: ftp.h:277
char m_mode
Definition: ftp.h:471
virtual PBoolean OnRMD(const PCaselessString &args)
File Transfer Protocol base class.
Definition: ftp.h:47
virtual PBoolean OnSTOU(const PCaselessString &args)
virtual void OnSyntaxError(PINDEX cmdNum)
Called for syntax errors in commands.
virtual PString GetHelloString(const PString &user) const
Get the string printed when a user logs in default value is a string giving the user name...
Definition: ftp.h:53
PIPSocket::Address m_remoteHost
Definition: ftp.h:464
bool OpenHost(const PString &host, WORD port=DefaultPort)
Open host using TCP.
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:61
bool m_thirdPartyPort
Definition: ftp.h:454
Definition: ftp.h:55
virtual PBoolean OnPWD(const PCaselessString &args)
Definition: ftp.h:53
PTCPSocket * GetFile(const PString &filename, DataChannelType channel=Passive)
Begin retreiving a file from the remote FTP server.
virtual PBoolean OnREIN(const PCaselessString &args)
WORD m_remotePort
Definition: ftp.h:465
virtual PBoolean OnDELE(const PCaselessString &args)
Definition: ftp.h:281
virtual PBoolean OnSTOR(const PCaselessString &args)
virtual PBoolean OnAPPE(const PCaselessString &args)
PTCPSocket * PutFile(const PString &filename, DataChannelType channel=Passive)
Begin storing a file to the remote FTP server.
PTCPSocket * GetURL(const PURL &url, RepresentationType type, DataChannelType channel=Passive)
Begin retreiving a file from the remote FTP server.
Commands
FTP commands.
Definition: ftp.h:52
Definition: ftp.h:458
PString m_readyString
Definition: ftp.h:453
Definition: ftp.h:457
Definition: ftp.h:53
char m_type
Definition: ftp.h:469
PBoolean CreateDirectory(const PString &path)
Create a directory on the remote FTP host.
virtual PBoolean OnSTAT(const PCaselessString &args)
virtual PBoolean OnRETR(const PCaselessString &args)
virtual PBoolean Close()
Close the socket, and if connected as a client, QUITs from server.
PStringArray GetDirectoryNames(NameTypes type=ShortNames, DataChannelType channel=Passive)
Get a list of files from the current working directory on the remote FTP host.
Definition: ftp.h:79
PString GetCurrentDirectory()
Get the current working directory on the remote FTP host.
PTCPSocket * PassiveClientTransfer(Commands cmd, const PString &args)
virtual PBoolean OnQUIT(const PCaselessString &args)
bool PBoolean
Definition: object.h:174
Definition: ftp.h:53
Definition: ftp.h:55
Definition: ftp.h:54
Definition: ftp.h:75
Definition: ftp.h:53
RepresentationType
Types for file transfer.
Definition: ftp.h:60
Definition: ftp.h:55
The character string class.
Definition: pstring.h:108
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:40
virtual PBoolean OnREST(const PCaselessString &args)
Definition: ftp.h:53
PFTPClient()
Declare an FTP client socket.
Definition: ftp.h:459
virtual PBoolean OnSYST(const PCaselessString &args)
PBoolean SendPORT(const PIPSocket::Address &addr, WORD port)
Send the PORT command for a transfer.
enum PFTPServer::@19 m_state
int m_illegalPasswordCount
Definition: ftp.h:473
Definition: ftp.h:54
PString m_userName
Definition: ftp.h:472
Definition: ftp.h:55
virtual void OnError(PINDEX errorCode, PINDEX cmdNum, const char *msg)
Handle an error in command.
Definition: ftp.h:54
A class describing an IP address.
Definition: ipsock.h:59
Definition: ftp.h:54
Definition: ftp.h:55
PBoolean ChangeDirectory(const PString &dirPath)
Change the current directory on the remote FTP host.
virtual PBoolean DispatchCommand(PINDEX code, const PString &args)
Dispatching to the appropriate virtual function.
Definition: ftp.h:54
Definition: ftp.h:63
PBoolean GetAllowThirdPartyPort() const
return the thirdPartyPort flag, allowing 3 host put and get.
Definition: ftp.h:307
virtual PBoolean OnRNTO(const PCaselessString &args)
virtual PBoolean OnLIST(const PCaselessString &args)
PFTPServer()
declare a server socket
void SendToClient(const PFilePath &filename)
Send the specified file to the client.
Definition: ftp.h:54
virtual PBoolean OnABOR(const PCaselessString &args)
Definition: ftp.h:56
virtual void OnCommandSuccessful(PINDEX cmdNum)
Called for successful commands.
void Construct()
virtual PBoolean OnSMNT(const PCaselessString &args)
PBoolean LogIn(const PString &username, const PString &password)
Log in to the remote host for FTP.
virtual PString GetGoodbyeString(const PString &user) const
return the string printed just before exiting
Definition: ftp.h:53
DataChannelType
File transfer mode on data channel.
Definition: ftp.h:67
Definition: ftp.h:69
PBoolean ProcessCommand()
Process commands, dispatching to the appropriate virtual function.
PBoolean OnOpen()
Call back to verify open succeeded in an PInternetProtocol class.
virtual PBoolean OnSTRU(const PCaselessString &args)
Definition: ftp.h:53
Definition: ftp.h:55
virtual PBoolean OnMODE(const PCaselessString &args)
This class describes a Universal Resource Locator.
Definition: url.h:56
virtual PBoolean OnPORT(const PCaselessString &args)
virtual PBoolean AuthoriseUser(const PString &user, const PString &password, PBoolean &replied)
Validate the user name and password for access.
virtual PBoolean OnACCT(const PCaselessString &args)
PString GetSystemType()
Get the type of the remote FTP server system, eg Unix, WindowsNT etc.
virtual PBoolean OnMKD(const PCaselessString &args)
virtual PBoolean OnOpen()
Call back to verify open succeeded in an PInternetProtocol class.
virtual PBoolean OnPASS(const PCaselessString &args)
Definition: ftp.h:62
virtual PBoolean OnUnknown(const PCaselessString &command)
Handle an unknown command.
Definition: ftp.h:53
Definition: ftp.h:54
Definition: ftp.h:54
Definition: ftp.h:53