how I use QFtp

Started by Mejda, May 14, 2012, 06:39:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mejda

Hi Liviu,
I know you are not a human network but I ask because you use signals and slots so when I use in QFtp  class  methode connecttohost I should link it to a signal.
thank you :)

Liviu Lalescu

#16
Hello :)

Of course, I'll try to help as my time permits, but you also need to go through the Qt documentation when necessary and read existing FET code.

Referring to code for FET version 5.18.0, in file src/interface/fetmainform.cpp:

In lines 519-526, if the user selected that FET should check for updates, so FET needs to get the crtversion.txt file from the FET homepage, I prepare for getting the file. When the file will be available (the program got it from the server), the finished signal will be emitted and the replyFinished slot will be called (see line 521). The signal belongs to the networkManager, the slot belongs to the FetMainForm.

Then, when the slot is called, I work on the file which was retrieved from the server (see lines 642-704).

Was that your question, or you meant something else?

Please let me know.

Mejda

Hi,
yes I refer to documetation of Qt and also class fetmainform but I inderstand that when you called a local function (in your case get) you don't link it to a signal
and my case I just use a local functions to QFtp class (like connect to host, put etc)  so I am not forced to link those function (connect to host,put,...) to signal
bref this is my code :

QFtp *ftp = new QFtp(this);
     //connect(ftp,SIGNAL(commandFinished ( int, bool)),this,SLOT(fincommande()));
     ftp->connectToHost("ftp.icwus.net");
     ftp->login("mylogin","passwd");
     ftp->cd("acrgafsa");
     int i = 0;
     QString filename;
     QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
     "D://");

     if (files.isEmpty())
     return;

     while(files.indexOf("/", i) != (-1)) //find the file name not include the full url
     i = files.indexOf("/",i) + 1;
     while(i < files.size())
     {
     filename.append(files.at(i));
     i++;
     }

     QFile *file = new QFile(filename);
     Q_ASSERT(file != NULL);

     if(!file->open(QIODevice::ReadWrite)) //finished create the file in the debug file
     {
     qDebug() << "opern err" << file->fileName();
     return;
     }
      qDebug() << "start upload";
     ftp->put(file,filename);
     qDebug() << "fin upload";
     ftp->close();


I have in output of program "start upload" and "fin upload" but in server I have'nt any file uploaded
I am not inderstand where the problem in my program
thank you for response :)

Liviu Lalescu

I think that the ftp->put command will exit immediately, and the ftp object will emit a 'done' or similar signal when finished, and you need to connect that signal to a slot, and in the slot you can do your work (you enter this slot after the transfer was done). But I am not sure.

If you didn't work too much with QFtp, Qt recommends to use QNetworkAccessManager instead, so a good thing would be to change to the recommended class.

I hope other programmers here can help you with better advice than me.

PS: I remind you: There is a special tag here on the forum to enclose C++ code, it is a button with the '#' sign on it. You need to enclose your code between this tag and your code will look nicer on the forum (I mean if you write directly code in the message, not when attaching it).

PPS: The correct English sentence is "I do not understand" (please forgive me for the correction :) )

Liviu Lalescu