00001
#ifndef FTPCLIENT_HPP
00002
#define FTPCLIENT_HPP
00003
00004
#if HAVE_CONFIG_H
00005
#include "config.h"
00006
#endif
00007
00008
#include <qdns.h>
00009
#include <qfile.h>
00010
#include <qhostaddress.h>
00011
#include <qsocket.h>
00012
#include <qsocketnotifier.h>
00013
#include <qstring.h>
00014
00015
#include "FTPListen.h"
00016
00017 class CFTPClient:
public QObject
00018 {
00019 Q_OBJECT
00020
public:
00021 enum Commands {
00022
cmdNop,
00023
cmdLogin,
00024
cmdLogout,
00025
cmdSetType,
00026
cmdChangeDir,
00027
cmdListDir,
00028
cmdUpload,
00029
cmdDownload,
00030
cmdRename,
00031
00032
00033
cmdPassive,
00034
cmdDeleteLocalFile,
00035
cmdDestroy,
00036 };
00037
00038 enum States {
00039
stNOC,
00040
stDNSBusy,
00041
stConnecting,
00042
stConnected,
00043
stLogin,
00044
stAuthenticate,
00045
00046
stIdle,
00047
00048
stSendingPort,
00049
stWaitData,
00050
stTransfer,
00051
stClosingData,
00052
00053
stFailed,
00054
stUnknown,
00055 };
00056
00057 enum TransferMethods {
00058
tmUnknown,
00059
tmAscii,
00060
tmBinary,
00061 };
00062
00063
private:
00064 QString m_UserName, m_Password;
00065 QString m_ServerName;
00066
int m_ServerPort;
00067
00068 QSocket *m_pCtrlFD;
00069
int m_DataFD;
00070 QSocketNotifier *m_pDataConnectNotifier;
00071 QSocketNotifier *m_pDataNotifier;
00072
CFTPListen *m_pListenFD;
00073 QFile m_LocalFile;
00074 QHostAddress m_MyAddress;
00075
00076
char *inputbuffer, *linebuffer;
00077 QString m_ResponseBuffer;
00078
char LastChar;
00079
int LineLen;
00080
int Response;
00081 QString RemoteFileName;
00082
00083
bool m_Passive;
00084 QHostAddress m_PassiveAddress;
00085 Q_UINT16 m_PassivePort;
00086
00087 QString outputbuffer;
00088
00089
char *m_TransferBuffer;
00090
int m_TransferBufferSize, m_TransferBufferHead, m_TransferBufferUsed;
00091
int TotalTransfered;
00092
00093 TransferMethods m_TransferMethod;
00094 States CurrentState;
00095 Commands CurrentCommand;
00096
00097
bool m_Log;
00098
00099
void InitBuffers();
00100
void CloseAllFD();
00101
void SetupControl();
00102
void CloseControl();
00103
bool SetupListen();
00104
void CloseListen();
00105
bool SetupLocal(
const QString &filename,
bool write,
bool truncate =
true);
00106
void CloseLocal();
00107
bool SetupDataActive();
00108
bool SetupDataPassive();
00109
void CloseData();
00110
void HookData();
00111
00112
void SetState(States new_st,
int response = 0);
00113
00114
void InterpretLine();
00115
void InterpretResponse();
00116
00117
void Send();
00118
void SendUser();
00119
void SendPass();
00120
void SendList();
00121
void SendPort(
const QHostAddress &, Q_UINT16 port);
00122
void SendStore(
const QString &filename);
00123
00124
void StartSending();
00125
void StartReceiving();
00126
00127
private slots:
00128
void ControlRead();
00129
void ControlError(
int);
00130
void ControlResolved();
00131
void ControlConnected();
00132
void ControlClosed();
00133
00134
void ListenConnect();
00135
00136
void DataConnect(
int socket);
00137
void DataRead();
00138
void DataWrite();
00139
void DataClose();
00140
00141
public:
00142
static const char *CommandStr[];
00143
static const char *StateStr[];
00144
00145
CFTPClient(QObject *parent = 0,
const char *name = 0);
00146
~CFTPClient();
00147
00148
void SetLogging(
bool log);
00149
00150
int GetCommand() const;
00151
int GetState() const;
00152
void SetPassive();
00153
void SetActive();
00154
00155
void Connect(const QString &user, const QString &pass, const QString &server,
int port = 21);
00156
00157
void Upload(const QString &local_file, const QString &remote_file = QString::null);
00158
void SetTypeAscii();
00159
void SetTypeBinary();
00160
void ChangeDir(const QString &new_dir);
00161
void ListDir();
00162
void Rename(const QString &from, const QString &to);
00163
00164
void Logout();
00165
00166 QString GetErrorString(
int result) const;
00167
00168 signals:
00180
void StateChange(
int command,
int new_state,
int result, const QString &server_msg);
00181
00183
void LoggedIn();
00185
void LoginFailed();
00187
void ControlPortClosed();
00188
void TimeOut();
00189
00190
void ListDirEntry(const QString &filename);
00191
00193
void Progress(
int offset);
00194 };
00195
00196 #endif