How to Test Ftp server availability
I have a small requirement as i need to test Ftp availability using QNetworkAccessManager.
I was able to transfer file to server.But i need to test availability first and then transfer file..
How do i do that..Can anyone share a part of code or hints
Thanks in Advance
Thats good...But i want to login in to FTP if it is available.How do i do that with QNetworkAccessManager?
Try something like this:
@ QUrl url("ftp://server/files/jgevas_FTPTest.txt");
url.setUserName("login"); url.setPassword("password"); url.setPort(25); data = new QFile(file, this);
reply = manager.put(QNetworkRequest(url), data);@
Maybe, you should change the port number.
The above example sends the file to an ftp server.My requirement is different.If You are awre of QFtp ,we do connect to host and login in to ftp .I want similar functionality using QNAM.I should just be able to test with the given credentials whether it is accessible or not? How do i that? Hope u understand the requirement now..
The above example does everything you want, as you get
QNetworkReply reply .
In the next step you can do:
Did you check "authenticationRequired":http://qt-project.org/doc/qt-5/qnetworkaccessmanager.html#authenticationRequired ?
Until valid credentials are given the signal is emitted again and again. If I understood you correctly this can be used in your case.
The above examples does everything ..i get error from QNetworkReply as "NO ERROR". But i do not want to send that text file and verify the accessibility..
Here we use
@ reply = manager.put(QNetworkRequest(url), data);@
i want to send only the ftp address as
reply = manager.put or get (QNetworkRequest(url));
I am not sure what function to use whether it is get or put or something else..?
Let me give an example like i.e..the way we ping and find the accessibility of a network just with address
I would then use:
@QNetworkReply * QNetworkAccessManager::get(const QNetworkRequest & request)@
That signal emits only if authentication either username or password set mismatches.What i need is i want is on button click need to just login in to ftp server and on another button click logout from ftp server.
hi i did test that but of no use.Here is my code...
@ QUrl testFtp("ftp://"+server);
// reply = manager.put(request,testData);
reply = manager.get(request);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(slotError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),this, SLOT(slotSslErrors(QList<QSslError>)));@
i get the error in Network Error says "202".
Well then another way would be to try to download file from ftp server. If it exists then on finished signal you should get NoError
void MainWindow::replyFinished(QNetworkReply *reply)
qDebug() << "Reply: " << reply->error(); //will show 0
thats not the way i guess.We just have an ip address,user,password.Just we need to ensure whether we are reachable to the server or not..We do not know what are the contents in ftp.So we cant download a file.
So cant we just login or connect to ftp server using QNAM?
What about the QNetworkSession? I could not understand this..can u suggest something else
Thanks for ur interest p3c0
Another way would be to try to connect the server using QTcpSocket as
QTcpSocket *socket = new QTcpSocket;
qDebug() << "Not connected";
If it succeeds then onConnected will be called immediately. But not sure if this is the recommended way.
Let me know if u get any from QNAM or supporting ones
Any updates on the previous ???
And i would like to add one more to this as..
When the network we try to connect is not in reach it does not give error on time..It takes a lot of time and some times it never returns any error..How do i handle this?
@ connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(slotError(QNetworkReply::NetworkError)));@
i am catching above signal which takes a lot of time...
Are there any best methods?
Try to use QTimer ?
i feel there will be a straight way to do it with QNetworkAccessManager or with QNetworkReply.Probably we are missing that..