Greeting
Im trying to download file with QT 4.8
and VS 2008
but i cant, It fail all the time.
I use following code to download file from FTP server.
void FTP::download(QString strFileName, QString strFTPFileName)
{
QFile * file = new QFile(strFileName);
if (m_fFile->open(QIODevice::ReadWrite))
{
QString strFtpServerIPAddress("192.168.7.10");
QString strFtpServerPortNumber("21");
QString strFtpUserName("admin");
QString strFtpPassword("admin");
QString strFtpFolderPath("\outgoing\");
qint16 iFtpPort = 21;
QFtp * ftp = new QFtp();
connect(ftp, SIGNAL(stateChanged(int)),SLOT(onStateChanged(int)));
connect(ftp, SIGNAL(done(bool)),SLOT(onDone(bool)));
connect(m_objFtp, SIGNAL(commandFinished(int, bool)),SLOT(onCommandFinished(int, bool)));
int iConnectToHostID = ftp->connectToHost(strFtpServerIPAddress, iFtpPort);
int iLogInID = ftp->login(strFtpUserName, strFtpPassword);
int iChangeDirectoryID = ftp->cd(strFtpFolderPath);
QFileInfo fileInfo(strFTPFileName);
QString strFileNameOnly(fileInfo.fileName());
int iOperationID = ftp->get(strFileNameOnly, file);
QEventLoop loop;
connect(this, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
ftp->close();
file->close();
delete ftp;
}
}
void FTP::onDone(bool bError)
{
...
//If "id" (saved from onStateChanged) is equal to "iOperationID", I emit "finished" Signal
...
}
I was checking onCommandFinished
slot and all steps (HostLookup, Connecting, Connected, LoggedIn) finish without error but exactly in get
operation, error
is true
and when i get detail about error with following codes ,
string strReason = QFtp::errorString().toStdString();
int iError = QFtp::error();
strReason
is Unknown error
and iError
is 0
.
Any idea what is going wrong here ?
Thanks in advanced
EDIT 1
I found the problem. Some how i cant download file from root directory, If i try to download file inside another directory, It work.
In my code , I check if strFtpFolderPath
is empty or equal to ".", In this case i change directory with ftp->cd("/")
other wise i set it to given path.
Any idea why i cant download file from root directory?