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 00145 bool ftpLogin(bool* userChanged = 0); 00146 00156 bool ftpSendCmd( const QByteArray& cmd, int maxretries = 1 ); 00157 00164 bool ftpSize( const QString & path, char mode ); 00165 00170 bool ftpFileExists(const QString& path); 00171 00175 bool ftpFolder(const QString& path, bool bReportError); 00176 00188 bool ftpOpenCommand( const char *command, const QString & path, char mode, 00189 int errorcode, KIO::fileoffset_t offset = 0 ); 00190 00197 bool ftpCloseCommand(); 00198 00205 bool ftpDataMode(char cMode); 00206 00207 //void ftpAbortTransfer(); 00208 00212 int ftpOpenDataConnection(); 00213 00217 void ftpCloseDataConnection(); 00218 00222 int ftpOpenPASVDataConnection(); 00226 int ftpOpenEPSVDataConnection(); 00230 int ftpOpenEPRTDataConnection(); 00234 int ftpOpenPortDataConnection(); 00235 00242 int ftpAcceptConnect(); 00243 00244 bool ftpChmod( const QString & path, int permissions ); 00245 00246 // used by listDir 00247 bool ftpOpenDir( const QString & path ); 00251 bool ftpReadDir(FtpEntry& ftpEnt); 00252 00256 void ftpCreateUDSEntry( const QString & filename, FtpEntry& ftpEnt, KIO::UDSEntry& entry, bool isDir ); 00257 00258 void ftpShortStatAnswer( const QString& filename, bool isDir ); 00259 00260 void ftpStatAnswerNotFound( const QString & path, const QString & filename ); 00261 00267 bool ftpRename( const QString & src, const QString & dst, KIO::JobFlags flags ); 00268 00274 bool ftpOpenControlConnection(); 00275 bool ftpOpenControlConnection( const QString & host, int port ); 00276 00280 void ftpCloseControlConnection(); 00281 00290 const char* ftpResponse(int iOffset); 00291 00303 StatusCode ftpGet(int& iError, int iCopyFile, const KUrl& url, KIO::fileoffset_t hCopyOffset); 00304 00315 StatusCode ftpPut(int& iError, int iCopyFile, const KUrl& url, int permissions, KIO::JobFlags flags); 00316 00325 StatusCode ftpCopyPut(int& iError, int& iCopyFile, const QString &sCopyFile, const KUrl& url, int permissions, KIO::JobFlags flags); 00326 00335 StatusCode ftpCopyGet(int& iError, int& iCopyFile, const QString &sCopyFile, const KUrl& url, int permissions, KIO::JobFlags flags); 00336 00343 StatusCode ftpSendMimeType(int& iError, const KUrl& url); 00344 00345 private: // data members 00346 00347 QString m_host; 00348 int m_port; 00349 QString m_user; 00350 QString m_pass; 00354 QString m_initialPath; 00355 KUrl m_proxyURL; 00356 00360 QString m_currentPath; 00361 00365 int m_iRespCode; 00366 00370 int m_iRespType; 00371 00376 char m_cDataMode; 00377 00381 bool m_bLoggedOn; 00382 00387 bool m_bTextMode; 00388 00399 bool m_bBusy; 00400 00401 bool m_bPasv; 00402 bool m_bUseProxy; 00403 00404 KIO::filesize_t m_size; 00405 static KIO::filesize_t UnknownSize; 00406 00407 enum 00408 { 00409 epsvUnknown = 0x01, 00410 epsvAllUnknown = 0x02, 00411 eprtUnknown = 0x04, 00412 epsvAllSent = 0x10, 00413 pasvUnknown = 0x20, 00414 chmodUnknown = 0x100 00415 }; 00416 int m_extControl; 00417 00421 QTcpSocket *m_control; 00422 QByteArray m_lastControlLine; 00423 00427 QTcpSocket *m_data; 00428 00432 QTcpServer *m_server; 00433 }; 00434 00435 #endif // KDELIBS_FTP_H 00436
KDE 4.7 API Reference