I'm trying to create a ftp client for multiple user accounts. While adding a user account, I need to check whether the host and user details are valid or not. For that I created a method.
bool FtpConnect::checkConnectivity(QString remoteIP, QString username, QString password)
{
QUrl server;
server.setScheme("ftp");
server.setHost(remoteIP);
if (!server.isValid()) {
QMessageBox::warning(0, "Error", "Invalid Host");
return false;
}
server.setPort(21);
server.setUserName(username);
server.setPassword(password);
QFtp *ftp = new QFtp(this);
ftp->connectToHost(server.host(), server.port());
int status = ftp->login(server.userName(), server.password());
QMessageBox::information(0, "Updated", QString::number(status));
return (ftp->list() == 4) ? true : false;
}
I need the code to return true if the connection is ok and false while the connection could not complete. Noe the variable status
returns 4
which is the QFtp::Connecting
signal. please somebody help me.