KIOSlave
ftp.h
Go to the documentation of this file.
00001 // -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 2; -*- 00002 /* This file is part of the KDE libraries 00003 Copyright (C) 2000 David Faure <faure@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library 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 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #ifndef KDELIBS_FTP_H 00022 #define KDELIBS_FTP_H 00023 00024 #include <config.h> 00025 00026 #include <sys/types.h> 00027 #include <sys/socket.h> 00028 00029 #include <kurl.h> 00030 #include <kio/slavebase.h> 00031 class QTcpServer; 00032 class QTcpSocket; 00033 00034 struct FtpEntry 00035 { 00036 QString name; 00037 QString owner; 00038 QString group; 00039 QString link; 00040 00041 KIO::filesize_t size; 00042 mode_t type; 00043 mode_t access; 00044 time_t date; 00045 }; 00046 00047 //=============================================================================== 00048 // Ftp 00049 //=============================================================================== 00050 class Ftp : public KIO::SlaveBase 00051 { 00052 // Ftp() {} 00053 00054 public: 00055 Ftp( const QByteArray &pool, const QByteArray &app ); 00056 virtual ~Ftp(); 00057 00058 virtual void setHost( const QString& host, quint16 port, const QString& user, const QString& pass ); 00059 00066 virtual void openConnection(); 00067 00071 virtual void closeConnection(); 00072 00073 virtual void stat( const KUrl &url ); 00074 00075 virtual void listDir( const KUrl & url ); 00076 virtual void mkdir( const KUrl & url, int permissions ); 00077 virtual void rename( const KUrl & src, const KUrl & dst, KIO::JobFlags flags ); 00078 virtual void del( const KUrl & url, bool isfile ); 00079 virtual void chmod( const KUrl & url, int permissions ); 00080 00081 virtual void get( const KUrl& url ); 00082 virtual void put( const KUrl& url, int permissions, KIO::JobFlags flags ); 00083 //virtual void mimetype( const KUrl& url ); 00084 00085 virtual void slave_status(); 00086 00090 virtual void copy( const KUrl &src, const KUrl &dest, int permissions, KIO::JobFlags flags ); 00091 00092 private: 00093 // ------------------------------------------------------------------------ 00094 // All the methods named ftpXyz are lowlevel methods that are not exported. 00095 // The implement functionality used by the public high-level methods. Some 00096 // low-level methods still use error() to emit errors. This behaviour is not 00097 // recommended - please return a boolean status or an error code instead! 00098 // ------------------------------------------------------------------------ 00099 00104 typedef enum { 00105 statusSuccess, 00106 statusClientError, 00107 statusServerError 00108 } StatusCode; 00109 00113 typedef enum { 00114 loginDefered, 00115 loginExplicit, 00116 loginImplicit 00117 } LoginMode; 00118 00129 bool ftpOpenConnection (LoginMode loginMode); 00130 00134 void ftpAutoLoginMacro (); 00135 00143 bool ftpLogin(); 00144 00154 bool ftpSendCmd( const QByteArray& cmd, int maxretries = 1 ); 00155 00162 bool ftpSize( const QString & path, char mode ); 00163 00168 bool ftpFileExists(const QString& path); 00169 00173 bool ftpFolder(const QString& path, bool bReportError); 00174 00186 bool ftpOpenCommand( const char *command, const QString & path, char mode, 00187 int errorcode, KIO::fileoffset_t offset = 0 ); 00188 00195 bool ftpCloseCommand(); 00196 00203 bool ftpDataMode(char cMode); 00204 00205 //void ftpAbortTransfer(); 00206 00210 int ftpOpenDataConnection(); 00211 00215 void ftpCloseDataConnection(); 00216 00220 int ftpOpenPASVDataConnection(); 00224 int ftpOpenEPSVDataConnection(); 00228 int ftpOpenEPRTDataConnection(); 00232 int ftpOpenPortDataConnection(); 00233 00240 int ftpAcceptConnect(); 00241 00242 bool ftpChmod( const QString & path, int permissions ); 00243 00244 // used by listDir 00245 bool ftpOpenDir( const QString & path ); 00249 bool ftpReadDir(FtpEntry& ftpEnt); 00250 00254 void ftpCreateUDSEntry( const QString & filename, FtpEntry& ftpEnt, KIO::UDSEntry& entry, bool isDir ); 00255 00256 void ftpShortStatAnswer( const QString& filename, bool isDir ); 00257 00258 void ftpStatAnswerNotFound( const QString & path, const QString & filename ); 00259 00265 bool ftpRename( const QString & src, const QString & dst, KIO::JobFlags flags ); 00266 00272 bool ftpOpenControlConnection(); 00273 bool ftpOpenControlConnection( const QString & host, int port ); 00274 00278 void ftpCloseControlConnection(); 00279 00288 const char* ftpResponse(int iOffset); 00289 00301 StatusCode ftpGet(int& iError, int iCopyFile, const KUrl& url, KIO::fileoffset_t hCopyOffset); 00302 00313 StatusCode ftpPut(int& iError, int iCopyFile, const KUrl& url, int permissions, KIO::JobFlags flags); 00314 00323 StatusCode ftpCopyPut(int& iError, int& iCopyFile, const QString &sCopyFile, const KUrl& url, int permissions, KIO::JobFlags flags); 00324 00333 StatusCode ftpCopyGet(int& iError, int& iCopyFile, const QString &sCopyFile, const KUrl& url, int permissions, KIO::JobFlags flags); 00334 00335 private: // data members 00336 00337 QString m_host; 00338 int m_port; 00339 QString m_user; 00340 QString m_pass; 00344 QString m_initialPath; 00345 KUrl m_proxyURL; 00346 00350 QString m_currentPath; 00351 00355 int m_iRespCode; 00356 00360 int m_iRespType; 00361 00366 char m_cDataMode; 00367 00371 bool m_bLoggedOn; 00372 00377 bool m_bTextMode; 00378 00389 bool m_bBusy; 00390 00391 bool m_bPasv; 00392 bool m_bUseProxy; 00393 00394 KIO::filesize_t m_size; 00395 static KIO::filesize_t UnknownSize; 00396 00397 enum 00398 { 00399 epsvUnknown = 0x01, 00400 epsvAllUnknown = 0x02, 00401 eprtUnknown = 0x04, 00402 epsvAllSent = 0x10, 00403 pasvUnknown = 0x20, 00404 chmodUnknown = 0x100 00405 }; 00406 int m_extControl; 00407 00411 QTcpSocket *m_control; 00412 QByteArray m_lastControlLine; 00413 00417 QTcpSocket *m_data; 00418 00422 QTcpServer *m_server; 00423 }; 00424 00425 #endif // KDELIBS_FTP_H 00426
KDE 4.6 API Reference