1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
class TW_ClientFTP : public QObject
{
Q_OBJECT
public:
TW_ClientFTP(QObject *parent);
void getOS();
signals:
//void done();
private slots:
void processReply(int replycode, const QString &detail);
void TW_ClientFTPdone(bool err);
void SLOT_ftpCommandEnded(int id, bool error);
void SLOT_newState(int state);
void SLOT_ftpCommandStarted(int id);
private:
QFtp *ftp;
};
TW_ClientFTP::TW_ClientFTP(QObject *parent) : QObject(parent)
{
ftp = new QFtp(this);
connect(ftp, SIGNAL(rawCommandReply(int, const QString &)),this, SLOT(processReply(int, const QString &)));
connect(ftp, SIGNAL(done(bool)),this, SLOT(TW_ClientFTPdone(bool)));
connect(ftp, SIGNAL(commandStarted(int)), this, SLOT(SLOT_ftpCommandStarted(int)));
connect(ftp, SIGNAL(commandFinished(int, bool )), this, SLOT(SLOT_ftpCommandEnded(int , bool )));
connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(SLOT_newState(int)));
}
void TW_ClientFTP::SLOT_newState(int state)
{
char *State[]={"Unconnected","HostLookup","Connecting","Connected","LoggedIn","Closing"};
printf("state: %s\n",State[state]);
}
void TW_ClientFTP::SLOT_ftpCommandStarted(int id)
{
char *cde[]={"None","SetTransferMode","SetProxy","ConnectToHost","Login","Close","List","Cd","Get","Put","Remove","Mkdir","Rmdir","Rename","RawCommand"};
printf("Command[%d]: %s\n",id,cde[ftp->currentCommand()]);
}
void TW_ClientFTP::SLOT_ftpCommandEnded(int id, bool error)
{
char *err[]={"NoError","HostNotFound","ConnectionRefused","NotConnected","UnknownError"};
printf("end_Command[%d]: %s\n",id,err[error]);
}
void TW_ClientFTP::TW_ClientFTPdone(bool err)
{
printf("Error : %s\n",ftp->errorString().toStdString().c_str());
//emit done();
}
void TW_ClientFTP::processReply(int n, const QString &rep)
{
printf("Rep[%d] : %s\n",n,rep.toStdString().c_str());
}
void TW_ClientFTP::getOS()
{
ftp->clearPendingCommands();
ftp->connectToHost(host,port);
ftp->login (user,passWord);
ftp->rawCommand("GETOS");
ftp->close();
} |
Partager