Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

pftpclient.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2004  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _pftpclient_h_
00021 #define _pftpclient_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/ptypes.h>
00025 #include <pclasses/psocket.h>
00026 #include <pclasses/purl.h>
00027 #include <memory>
00028 #include <iostream>
00029 #include <string>
00030 #include <list>
00031 
00032 namespace P {
00033 
00035 
00038 class PNET_EXPORT FTPError: public RuntimeError {
00039   public:
00040     FTPError(const char* what, const std::list<std::string>& text,
00041              const SourceInfo& si) throw();
00042 
00043     ~FTPError() throw();
00044 
00045     inline BaseError* clone() const
00046     { return new FTPError(*this); }
00047 
00048     inline const std::string& text() const
00049     { return m_text; }
00050 
00051   private:
00052     std::string m_text;
00053 };
00054 
00055 
00057 
00060 class PNET_EXPORT FTPResponse {
00061   public:
00062     FTPResponse(unsigned int code, std::list<std::string>& text);
00063     ~FTPResponse();
00064 
00066     inline unsigned int code() const
00067     { return m_code; }
00068 
00069     inline bool isPositivePreliminary() const
00070     { return (m_code >= 100 && m_code < 200); }
00071 
00072     inline bool isPositiveCompletion() const
00073     { return (m_code >= 200 && m_code < 300); }
00074 
00075     inline bool isPositiveIntermediate() const
00076     { return (m_code >= 300 && m_code < 400); }
00077 
00078     inline bool isNegativeTransient() const
00079     { return (m_code >= 400 && m_code < 500); }
00080 
00081     inline bool isNegativePermanent() const
00082     { return (m_code >= 500 && m_code < 600); }
00083 
00084     inline const std::list<std::string>& text() const
00085     { return m_text; }
00086 
00087     friend PNET_EXPORT std::ostream& operator<<(std::ostream& os, const FTPResponse& resp);
00088 
00089   private:
00090     unsigned int            m_code;
00091     std::list<std::string>  m_text;
00092 
00093 };
00094 
00095 class FTPClient;
00096 
00098 
00101 class PNET_EXPORT FTPData: public StreamSocket {
00102   public:
00103     FTPData(FTPClient* cl, StreamSocketServer& srv) throw(IOError);
00104     FTPData(FTPClient* cl, const NetworkAddress& addr, port_t port) throw(IOError);
00105 
00106     ~FTPData() throw();
00107 
00108     size_t write(const char* buffer, size_t count) throw(IOError);
00109 
00110     size_t read(char* buffer, size_t count) throw(IOError);
00111 
00112   private:
00113     FTPClient*  m_client;
00114 };
00115 
00117 
00120 class PNET_EXPORT FTPClient: protected StreamSocket {
00121   public:
00123     enum transMode_t {
00124       ModeStream,
00125       ModeBlock,
00126       ModeCompressed
00127     };
00128 
00129     enum transType_t {
00130       TypeASCII,
00131       TypeEBCDIC,
00132       TypeImage
00133     };
00134 
00135     enum dataMode_t {
00136       Passive,
00137       Active
00138     };
00139 
00140     FTPClient(int domain) throw(IOError);
00141     FTPClient(const NetworkAddress& addr, port_t port) throw(IOError);
00142     ~FTPClient() throw();
00143 
00144     void connect(const NetworkAddress& addr, port_t port) throw(IOError, FTPError);
00145 
00146     void close() throw(IOError);
00147 
00148     void sendCmd(const std::string& cmd) throw(IOError);
00149     const FTPResponse* readResponse() throw(IOError);
00150 
00151     const FTPResponse* lastResponse();
00152 
00153     void login(const std::string& user, const std::string& passwd,
00154                const std::string& account = "") throw(IOError, FTPError);
00155 
00156     void logout() throw(IOError, FTPError);
00157 
00158     void setMode(transMode_t mode) throw(IOError, FTPError);
00159 
00160     inline transMode_t mode() const throw()
00161     { return m_transMode; }
00162 
00163     void setType(transType_t type) throw(IOError,FTPError);
00164 
00165     inline transType_t type() const throw()
00166     { return m_transType; }
00167 
00169 
00173     std::string cwd() throw(IOError, FTPError);
00174 
00176     void chdir(const std::string& path) throw(IOError, FTPError);
00177 
00179     void cdup() throw(IOError, FTPError);
00180 
00182 
00187     void mkdir(const std::string& path) throw(IOError, FTPError);
00188 
00190 
00195     void rmdir(const std::string& path) throw(IOError, FTPError);
00196 
00198     void remove(const std::string& path) throw(IOError, FTPError);
00199 
00201     FTPData* dir(const std::string& path = "") throw(IOError, FTPError);
00202 
00203     FTPData* store(const std::string& path) throw(IOError, FTPError);
00204 
00205     FTPData* retrieve(const std::string& path) throw(IOError, FTPError);
00206 
00208 
00214     void noop() throw(IOError, FTPError);
00215 
00217     bool testResponse() throw(IOError);
00218 
00219     inline FTPData* dataConn() const throw()
00220     { return m_dataConn; }
00221 
00222   private:
00223     void initDataConn(const std::string& cmd) throw(IOError, FTPError);
00224 
00225     transMode_t   m_transMode;
00226     transType_t   m_transType;
00227     dataMode_t    m_dataMode;
00228     FTPData*      m_dataConn;
00229     FTPResponse*  m_lastResp;
00230 };
00231 
00232 }
00233 
00234 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3