[PyQt] QFtp putting multiple files

Tony Arnold tony.arnold at manchester.ac.uk
Sun Jan 19 11:16:07 GMT 2014


I'm trying to write some code that uses QFtp and transfers a number
files to the ftp site.

My code kicks off the put command and then execs a progress dialogue
box. I have a signal/socket that updates the progress dialogue box. I
also have a socket that executes when the put command has finished and
this hides the dialogue box.

The exec of the progress box returns under one of two conditions. Either
progress has 100% or the put command complete socket hides it.

The problem is that there is a race condition between these two. If
progress hits 100% before the signal for the put command termination
signal, then the next file gets processed, the progress box gets
displayed again, but then the put terminal signal gets in and hides the box.

It seems also, that the progress dialogue doesn't always hit 100%, so
without hiding it in the put command terminated socket, the whole thing
can sometimes hang up.

Here is some code. First the loop that puts the files:

                for fname in self.files:
                    fout=os.path.basename(fname)
                    message="Uploading '%s'"%fout
                    self.fp[fname]=QtCore.QFile(fname)
                    if self.fp[fname].open(QtCore.QIODevice.ReadOnly):
                        print("About to put: %s"%fout)
                        self.ftp.put(self.fp[fname],fout)
                        self.progressDialog.setLabelText("Uploading
%s..." % fout)
                        self.progressDialog.exec()
                        self.fp[fname].close()
                        print("Put method returned: %s"%fout)


and here is the socket that received the comand terminated signal:

    def ftpCommandFinished(self, _, error):

        if self.ftp.currentCommand() == QFtp.ConnectToHost:
            if error:
                QMessageBox.information(self, "FTP",
                        "Unable to connect to the FTP server.")
                return
            return

        if self.ftp.currentCommand() == QFtp.Put:
            print("Put command finished.")
            self.progressDialog.hide()


Any suggestions? Has anyone implement this kind of thing successfully?
All help much appreciated as I have Google'd this to death and not found
an answer.

Regards,
Tony.
-- 
Tony Arnold,                        Tel: +44 (0) 161 275 6093
Head of IT Security,                Fax: +44 (0) 705 344 3082
University of Manchester,           Mob: +44 (0) 773 330 0039
Manchester M13 9PL.                 Email: tony.arnold at manchester.ac.uk


More information about the PyQt mailing list