QFtp: Problem connecting to host
-
Sorry! Anyway: another guess, since you can connect ok but not locally, maybe it's because the traffic is too fast on your LAN, i.e. try to slow down the connection for example by inserting ProcessEvents:
QCoreApplication::ProcessEvents();
ftp->connectToHost(“192.168.0.232");
QCoreApplication::ProcessEvents();
ftp->login("anonymous", "ftp"); -
Hi,
What about waitForConnected ?
-
For some reason it is working now without doing anything. I have another problem though. It seems that there are no files or directories showing from the connected server. The Qt side says it is connected (how would I verify that it is actually connected?) and that the directory is empty. I know that it is not empty. I am not sure if it is not actually connected or if there is something extra needed to see what is in the directory?
EDIT:
Just for reference, I am using the below code to connect and it actually says I am connected and logged in. Not sure why the files and directories don't show...@void FtpWindow::connectToFtp()
{
//![1]
ftp = new QFtp(this);
connect(ftp, SIGNAL(commandFinished(int,bool)),
this, SLOT(ftpCommandFinished(int,bool)));
connect(ftp, SIGNAL(listInfo(QUrlInfo)),
this, SLOT(addToList(QUrlInfo)));
connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
this, SLOT(updateDataTransferProgress(qint64,qint64)));fileList->clear(); currentPath.clear(); isDirectory.clear();
//![1]
//![2]
QUrl url(ftpServerLineEdit->text());
if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
ftp->connectToHost(ftpServerLineEdit->text(), 21);
//ftp->login("anonymous", "ftp");
ftp->login();
QCoreApplication::processEvents(0, 100);
qDebug() << ftp->state();
} else {
ftp->connectToHost(url.host(), url.port(21));if (!url.userName().isEmpty()) ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password()); else ftp->login(); if (!url.path().isEmpty()) ftp->cd(url.path()); }
//![2]
if ( ftp->Connected ) { if ( ftp->LoggedIn ) { fileList->setEnabled(true); connectButton->setEnabled(false); connectButton->setText(tr("Disconnect")); statusLabel->setText(tr("Connecting to FTP server %1...") .arg(ftpServerLineEdit->text())); } else { connectButton->setEnabled(false); connectButton->setText(tr("Disconnect")); statusLabel->setText(tr("Not logged into FTP server %1...") .arg(ftpServerLineEdit->text())); } } else { statusLabel->setText(tr("Could not connect to FTP server %1...") .arg(ftpServerLineEdit->text())); }
}@
[quote author="hskoglund" date="1398452374"]Sorry! Anyway: another guess, since you can connect ok but not locally, maybe it's because the traffic is too fast on your LAN, i.e. try to slow down the connection for example by inserting ProcessEvents:
QCoreApplication::ProcessEvents();
ftp->connectToHost(“192.168.0.232");
QCoreApplication::ProcessEvents();
ftp->login("anonymous", "ftp");
[/quote] -
Hi. if you try the same connection from Internet Explorer, e.g. type "ftp://192.168.0.232" and that shows files/directories, then you cold check that the qFTP connection is real by opening a CMD window and type netstat, it should list 192.168.0.232:ftp .. ESTABLISHED.
If it's established and you don't see any files, try slowing down the traffic by doing those QCoreApplication::ProcessEvents()...EDIT: Oh, better is to try SGaist's suggestion waitForConnected() it's a good idea, because connectToHost() does not block.
-
I did as you suggested. I see the files in IE, however when I type netstat in the cmd window I do not see that IP as established...
[quote author="hskoglund" date="1398865570"]Hi. if you try the same connection from Internet Explorer, e.g. type "ftp://192.168.0.232" and that shows files/directories, then you cold check that the qFTP connection is real by opening a CMD window and type netstat, it should list 192.168.0.232:ftp .. ESTABLISHED.
If it's established and you don't see any files, try slowing down the traffic by doing those QCoreApplication::ProcessEvents()...EDIT: Oh, better is to try SGaist's suggestion waitForConnected() it's a good idea, because connectToHost() does not block.[/quote]
-
There is no such thing as waitForConnected().
EDIT: I was actually able to connect using the Qt program and when viewing the result of netstat I see that the connection was established. The only problem now is that I do not see any files.
[quote author="hskoglund" date="1398866292"]Ok try with ftp->waitForConnected() between connectToHost() and login()[/quote]
-
I am connected as shown by the netstat check that you suggested. The problem is I do not see files. Are you saying I need time for files to show or is that for connecting. If it is for connecting I already solved that issue. My new issue is just that it thinks the directory is empty.
[quote author="hskoglund" date="1398866758"]Sorry, nice try :-(
But there should be other ways to slow it down, for example, do the connectoToHost() in one function and login() in another...
[/quote] -
Do you also think it could be a matte of the remote server being an active or passive ftp connection? Maybe I have to manually get() the files individually??
[quote author="hskoglund" date="1398869401"]Hi, I think it needs more time for the files to show (because connectToHost() returns directly, so that login() perhaps is called too early).
[/quote]