0

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?

M.H.
  • 223
  • 3
  • 10
  • 23
  • `QString strFtpFolderPath("\outgoing\")` You have to escape the backslahes. – weeska Mar 15 '16 at 06:57
  • @weeska Still have same problem ! – M.H. Mar 15 '16 at 08:24
  • Maybe this helps: http://stackoverflow.com/questions/29233745/qt-qcoreapplication-and-qftp?rq=1 – weeska Mar 15 '16 at 08:31
  • @weeska Checked, Not really, I'm using signal-slots or even QEventLoop correctly. Even to be sure, I executed QEventLoop after all commands, connectToHost, login, cd and checked the result in onDone(bool bResult). They all finish without error (bError is equal to false). But get return with error and i have no idea what is wrong since it does not give me any information about it ... – M.H. Mar 15 '16 at 08:40
  • @weeska Check edit 1 please – M.H. Mar 15 '16 at 09:10

0 Answers0