Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

ftp.h

Go to the documentation of this file.
00001 // Copyright (C) 2001 Dr. Eckhardt + Partner GmbH
00002 //    
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software 
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00016 
00017 #ifndef CCXX_FTP_H_
00018 #define CCXX_FTP_H_
00019 
00020 #ifndef CCXX_SOCKET_H_
00021 #include <cc++/socket.h>
00022 #endif
00023 
00024 #include <string>
00025 #include <set>
00026 #include <iostream>
00027 #include <utility>
00028 
00029 #ifdef  CCXX_NAMESPACES
00030 namespace ost {
00031 #endif
00032 
00068 class FTPSocket
00069 {
00070 protected:
00071       TCPStream* cs;
00072 
00073       friend class oftpstream;
00074       friend class iftpstream;
00075       static int debug;
00076 
00077 public:
00078 
00082       void sendCommand(std::string cmd);
00083       int getResponse(std::string* resp = 0);
00084 
00088       FTPSocket();
00089 
00093       explicit FTPSocket(InetHostAddress host, timeout_t to = 0);
00094 
00098       FTPSocket(InetHostAddress host, std::string user, std::string passwd,
00099           timeout_t to = 0);
00100 
00104       ~FTPSocket();
00105 
00109       static void setDebug(int d = 1)  { debug = d; }
00110 
00114       static int  getDebug()           { return debug; }
00115 
00119       void setAscii();
00120 
00124       void setEbcdic();
00125 
00129       void setBinary();
00130 
00134       std::string Command(std::string cmd);
00135 
00139       class direntry
00140       {
00141       protected:
00142           std::string _line;
00143           std::string _access;
00144           std::string _user;
00145           std::string _group;
00146           std::string _name;
00147           unsigned int _size;
00148 
00149       public:
00150           struct _compare
00151           {
00152             bool operator()(const direntry& d1, const direntry& d2) const
00153             { return d1.getName() < d2.getName(); }
00154           };
00155 
00159           bool parse(std::string li);
00160 
00164           std::string  getLine() const    { return _line; }
00165           std::string  getAccess() const  { return _access; }
00166           std::string  getUser() const    { return _user; }
00167           std::string  getGroup() const   { return _group; }
00168           std::string  getName() const    { return _name; }
00169           unsigned int getSize() const    { return _size; }
00170 
00171           bool is_dir() const           { return _access[0] == 'd'; }
00172           bool is_link() const          { return _access[0] == 'l'; }
00173           bool can_userread() const     { return _access[1] == 'r'; }
00174           bool can_userwrite() const    { return _access[2] == 'w'; }
00175           bool can_groupread() const    { return _access[4] == 'r'; }
00176           bool can_groupwrite() const   { return _access[5] == 'w'; }
00177           bool can_otherread() const    { return _access[7] == 'r'; }
00178           bool can_otherwrite() const   { return _access[8] == 'w'; }
00179       };
00180 
00184       typedef set<direntry, direntry::_compare> dir_type;
00185 
00191       void Open(InetHostAddress host, timeout_t to = 0);
00192 
00196       void Open(InetHostAddress host, std::string user, std::string passwd,
00197                 timeout_t to = 0);
00198 
00202       void Login(std::string user, std::string passwd);
00203 
00207       void Close(void);
00208 
00212       void Quit(void);
00213 
00217       dir_type       getDir(std::string dir = "", timeout_t to = 0);
00218 
00222       std::string    pwd(void);
00223 
00227       void           cwd(std::string dir);
00228 
00232       void           cdup(void);
00233 
00237       void Put(std::string file, std::string rfilename, timeout_t to = 0);
00238 
00242       void Put(std::string file, timeout_t to = 0)
00243         { Put(file, file, to); }
00244 
00248       void Get(std::string file, std::string lfilename, timeout_t to = 0);
00249 
00253       void Get(std::string file, timeout_t to = 0)
00254         { Get(file, file, to); }
00255 
00259       void remove(std::string file);
00260 
00264       void rename(std::string from, std::string to);
00265 
00269       void mkdir(std::string dir);
00270 
00274       void rmdir(std::string dir);
00275 };
00276 
00280 class oftpstream : public tcpstream
00281 {
00282 protected:
00283       FTPSocket& ftpref;
00284 
00285 public:
00291       oftpstream(FTPSocket& f, std::string rfilename, int buffer = 512,
00292               timeout_t to = 0);
00293 
00297       ~oftpstream()
00298       { close(); }
00299 
00303       void close();
00304 };
00305 
00309 class iftpstream : public tcpstream
00310 {
00311 protected:
00312       FTPSocket& ftpref;
00313 
00314 public:
00318       iftpstream(FTPSocket& f, std::string rfilename, int buffer = 512,
00319               timeout_t to = 0);
00320 
00324       ~iftpstream()
00325       { close(); }
00326 
00330       void close();
00331 };
00332 
00333 #ifdef  COMMON_STD_EXCEPTION
00334 
00337 class FTPException : public SockException
00338 {
00339 public:
00340         FTPException(std::string str) : SockException(str) {};                   
00341 };
00342 
00346 class FTPResponse : public FTPException
00347 {
00348 protected:
00349       int code;
00350 public:
00351       FTPResponse(int c, std::string r) : FTPException(r), code(c) {};
00352 
00356       int getCode() const  { return code; }
00357 };
00358 #endif
00359 
00360 #ifdef  CCXX_NAMESPACES
00361 };
00362 #endif
00363 
00364 #endif

Generated at Thu Jan 24 11:06:01 2002 for CommonC++ by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001