PTLib  Version 2.10.10
 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  * $Revision: 25012 $
28  * $Author: rjongbloed $
29  * $Date: 2011-01-06 01:01:23 -0600 (Thu, 06 Jan 2011) $
30  */
31 
32 #ifndef PTLIB_FTP_H
33 #define PTLIB_FTP_H
34 
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38 
39 #include <ptclib/inetprot.h>
40 #include <ptlib/sockets.h>
41 
42 
43 class PURL;
44 
45 
49 class PFTP : public PInternetProtocol
50 {
51  PCLASSINFO(PFTP, PInternetProtocol);
52  public:
54  enum Commands {
59  };
60 
66  };
67 
72  };
73 
75  enum NameTypes {
78  };
79 
80  enum {
82  };
83 
88  const PIPSocket::Address & addr,
89  WORD port
90  );
91 
92 
93  protected:
95  PFTP();
96 };
97 
98 
102 class PFTPClient : public PFTP
103 {
104  PCLASSINFO(PFTPClient, PFTP);
105  public:
107  PFTPClient();
108 
110  ~PFTPClient();
111 
112 
120  virtual PBoolean Close();
121 
123 
128  bool OpenHost(
129  const PString & host,
130  WORD port = DefaultPort
131  );
132 
138  PBoolean LogIn(
139  const PString & username,
140  const PString & password
141  );
142 
149 
156  RepresentationType type
157  );
158 
165  const PString & dirPath
166  );
167 
174 
182  NameTypes type = ShortNames,
183  DataChannelType channel = Passive
184  );
192  const PString & path,
193  NameTypes type = ShortNames,
194  DataChannelType channel = Passive
195  );
196 
203  const PString & path
204  );
205 
212  const PString & path,
213  DataChannelType channel = Passive
214  );
215 
225  const PString & filename,
226  DataChannelType channel = Passive
227  );
228 
238  const PString & filename,
239  DataChannelType channel = Passive
240  );
241 
250  PTCPSocket * GetURL(
251  const PURL & url,
252  RepresentationType type,
253  DataChannelType channel = Passive
254  );
255 
257 
258  protected:
260  virtual PBoolean OnOpen();
261 
263  Commands cmd,
264  const PString & args
265  );
267  Commands cmd,
268  const PString & args
269  );
270 
273 };
274 
275 
279 class PFTPServer : public PFTP
280 {
281  PCLASSINFO(PFTPServer, PFTP);
282  public:
283  enum { MaxIllegalPasswords = 3 };
284 
286  PFTPServer();
287  PFTPServer(
288  const PString & readyString
289  );
290 
292  ~PFTPServer();
293 
294 
295  // New functions for class
300  virtual PString GetHelloString(const PString & user) const;
301 
303  virtual PString GetGoodbyeString(const PString & user) const;
304 
306  virtual PString GetSystemTypeString() const;
307 
310 
313 
322 
330  virtual PBoolean DispatchCommand(
331  PINDEX code,
332  const PString & args
333  );
334 
335 
343  PINDEX cmd
344  );
345 
354  virtual PBoolean AuthoriseUser(
355  const PString & user,
356  const PString & password,
357  PBoolean & replied
358  );
359 
366  virtual PBoolean OnUnknown(
367  const PCaselessString & command
368  );
369 
376  virtual void OnError(
377  PINDEX errorCode,
378  PINDEX cmdNum,
379  const char * msg
380  );
381 
383  virtual void OnSyntaxError(
384  PINDEX cmdNum
385  );
386 
388  virtual void OnNotImplemented(
389  PINDEX cmdNum
390  );
391 
393  virtual void OnCommandSuccessful(
394  PINDEX cmdNum
395  );
396 
397 
398  // the following commands must be implemented by all servers
399  // and can be performed without logging in
400  virtual PBoolean OnUSER(const PCaselessString & args);
401  virtual PBoolean OnPASS(const PCaselessString & args); // officially optional, but should be done
402  virtual PBoolean OnQUIT(const PCaselessString & args);
403  virtual PBoolean OnPORT(const PCaselessString & args);
404  virtual PBoolean OnSTRU(const PCaselessString & args);
405  virtual PBoolean OnMODE(const PCaselessString & args);
406  virtual PBoolean OnTYPE(const PCaselessString & args);
407  virtual PBoolean OnNOOP(const PCaselessString & args);
408  virtual PBoolean OnSYST(const PCaselessString & args);
409  virtual PBoolean OnSTAT(const PCaselessString & args);
410 
411  // the following commands must be implemented by all servers
412  // and cannot be performed without logging in
413  virtual PBoolean OnRETR(const PCaselessString & args);
414  virtual PBoolean OnSTOR(const PCaselessString & args);
415  virtual PBoolean OnACCT(const PCaselessString & args);
416  virtual PBoolean OnAPPE(const PCaselessString & args);
417  virtual PBoolean OnRNFR(const PCaselessString & args);
418  virtual PBoolean OnRNTO(const PCaselessString & args);
419  virtual PBoolean OnDELE(const PCaselessString & args);
420  virtual PBoolean OnCWD(const PCaselessString & args);
421  virtual PBoolean OnCDUP(const PCaselessString & args);
422  virtual PBoolean OnRMD(const PCaselessString & args);
423  virtual PBoolean OnMKD(const PCaselessString & args);
424  virtual PBoolean OnPWD(const PCaselessString & args);
425  virtual PBoolean OnLIST(const PCaselessString & args);
426  virtual PBoolean OnNLST(const PCaselessString & args);
427  virtual PBoolean OnPASV(const PCaselessString & args);
428 
429  // the following commands are optional and can be performed without
430  // logging in
431  virtual PBoolean OnHELP(const PCaselessString & args);
432  virtual PBoolean OnSITE(const PCaselessString & args);
433  virtual PBoolean OnABOR(const PCaselessString & args);
434 
435  // the following commands are optional and cannot be performed
436  // without logging in
437  virtual PBoolean OnSMNT(const PCaselessString & args);
438  virtual PBoolean OnREIN(const PCaselessString & args);
439  virtual PBoolean OnSTOU(const PCaselessString & args);
440  virtual PBoolean OnALLO(const PCaselessString & args);
441  virtual PBoolean OnREST(const PCaselessString & args);
442 
443 
445  void SendToClient(
446  const PFilePath & filename
447  );
448 
449 
450  protected:
452  PBoolean OnOpen();
453  void Construct();
454 
457 
458  enum {
464  } state;
465 
468 
470 
471  char type;
472  char structure;
473  char mode;
476 };
477 
478 
479 PFACTORY_LOAD(PURL_FtpLoader);
480 
481 
482 #endif // PTLIB_FTP_H
483 
484 
485 // End of File ///////////////////////////////////////////////////////////////