Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QFtp- can't download file I've just uploaded
Forum Updated to NodeBB v4.3 + New Features

QFtp- can't download file I've just uploaded

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jaszczomb
    wrote on last edited by
    #1

    Hi everyone,
    I'm working on a simple program, based on QFtp. The purpose of it's work is to store small flies on FTP server.
    I've wrote well working instructions for uploading and downloading files. Until I only download files by this program, things go alright (despite of progress pop-up showing twice). If I upload files and check if they are correctly uploaded by FTP client, I can see them and download (still by some ftp client), they aren't corrupted. Problem starts, when I try to download files uploaded before using only my program. When download progress starts, everything looks good but when it finishes I can only find empty file titled as downloaded file.
    I would be very grateful if anyone got some idea.

    Here's the code I use to upload and download:

    @
    void SimpleCloud::wyslij()
    {
    QString sciezka = ui->Usciezka->text();
    QString nazwa="";
    int a=0,i=0;
    for(i =0; i<sciezka.size(); i++)
    {
    if(sciezka.at(i)=='/')
    {
    qDebug()<<"slash na pozycji "<<i;
    a=i+1;
    }
    }
    qDebug()<<"n";
    for(i=a;i<sciezka.size();i++)
    {
    nazwa[i-a]=sciezka[i];
    }
    qDebug()<<"nazwa pliku to: "<<nazwa;
    plik = new QFile(sciezka);
    ftp->put(plik,nazwa);
    postep->setLabelText("Wysylanie "+nazwa);
    postep->exec();
    ui->statusBar->showMessage("Wysylanie");
    qDebug()<<"FTP: wysylanie";
    }

    void SimpleCloud::pobierz()
    {
    QString nazwa = ui->listaSerwer->currentItem()->text(0);
    QString sciezka = ui->Dsciezka->text();
    if(sciezka!="Ścieżka"&&sciezka!=NULL)
    {
    sciezka = sciezka + "/" + nazwa;
    plik = new QFile(sciezka);
    }
    else
    {
    plik = new QFile(nazwa);
    }
    if(!plik->open(QFile::WriteOnly))
    {
    ui->statusBar->showMessage("Blad pobierania pliku",1000);
    delete plik;
    return;
    }
    ui->statusBar->showMessage("Rozpoczynam pobieranie");
    ftp->get(ui->listaSerwer->currentItem()->text(0), plik);
    postep->setLabelText("Pobieranie "+nazwa);
    postep->exec();
    }
    @

    Edit
    In this code I've used Polish to name variables, methods etc. If necessary I can translate that to English.

    [EDIT: code formatting, please use @-tags instead of [code], Volker]

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vinb
      wrote on last edited by
      #2

      Hi,
      i dont react on your code, but i find it very helpfull to connect the ftp.done() to your own code and then you can see if theres a problem at ftp side. like the example program does.

      @
      in .h
      signals:
      done();

      private slots:
      void ftpDone(bool error);


      in constructor:
      connect(&ftp, SIGNAL(done(bool)),this,SLOT(ftpDone(bool)));

      in slot:
      void SimpleCloud::ftpDone(bool error)
      {
      if (error) {
      std::cerr << "ERROR: " << qPrintable(ftp.errorString())
      << std::endl;
      } else {
      std::cerr << "File downloaded as "
      << qPrintable(plik.fileName())
      << std::endl;
      }
      plik.close();
      emit done();
      }

      @

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jaszczomb
        wrote on last edited by
        #3

        I did as you said and my program is unexpectedly stopping. I'll what have I done wrong and try to build it.

        edit
        It seems that I've got a segmentation fault while connecting done(bool) with ftpDone(bool)

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vinb
          wrote on last edited by
          #4

          did you include iostream to use std:cerr?

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jaszczomb
            wrote on last edited by
            #5

            No, I've used qDebug(); which I'm using in whole project. As I edited my previous post it's about connecting. What could be wrong?

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vinb
              wrote on last edited by
              #6

              my quess is that the filename is wrong, i did also encounterd that. But that was retrieving the name out of an url. So slightly dfferent, cause you select it.
              make sure the name is not "/file.name" but "file.name"

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vinb
                wrote on last edited by
                #7

                [quote author="jaszczomb" date="1306339228"]I did as you said and my program is unexpectedly stopping. I'll what have I done wrong and try to build it.

                edit
                It seems that I've got a segmentation fault while connecting done(bool) with ftpDone(bool)[/quote]

                -sorry dont know,
                it works with me-

                i edited my last code, change in .h

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  jaszczomb
                  wrote on last edited by
                  #8

                  You mean filename while uploading or downloading the file?
                  While sending file to FTP server I'm checking filename at
                  @
                  QString sciezka = ui->Usciezka->text();
                  QString nazwa="";
                  int a=0,i=0;
                  for(i =0; i<sciezka.size(); i++)
                  {
                  if(sciezka.at(i)=='/')
                  {
                  qDebug()<<"slash na pozycji "<<i;
                  a=i+1;
                  }
                  }
                  qDebug()<<"\n";
                  for(i=a;i<sciezka.size();i++)
                  {
                  nazwa[i-a]=sciezka[i];
                  }
                  qDebug()<<"nazwa pliku to: "<<nazwa;@
                  And filename at last line is correct, without slash. I can also download file (by FTP client as gFTP) I've uploaded using by my program so I don't think that's about filename.

                  edit
                  is that possible that's about Qt Creator version or OS?

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jaszczomb
                    wrote on last edited by
                    #9

                    Refreshing

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved