[PyQt] How to add ftp put function in PyQT network ftp demo

不坏阿峰 onlydebian at gmail.com
Tue Jul 1 12:42:14 BST 2014


thanks to ur reply.

i have try use self.ftp.put(self.filename, up_fname) at the beginning. this
works. only the file name in the file uploaded on server, not correct.


2014-07-01 17:50 GMT+07:00 Robert Kent <rob at gulon.co.uk>:

> You need to keep the handle to your QFile object in scope. The put()
> method returns straight away and the data to be put is added to a queue and
> uploaded in the background. Your selectFile() method returns straight away
> therefore your upload_file object goes out of scope before it can be sent.
> Simply changing upload_file to self.upload_file will solve your problem.
>
> Hope this helps ;o)
> Rob
>
>
> From: 不坏阿峰 <onlydebian at gmail.com>
> Date: Tuesday, 1 July 2014 03:30
> To: <pyqt at riverbankcomputing.com>
> Subject: [PyQt] How to add ftp put function in PyQT network ftp demo
>
> I want to modify the pyqt network ftp demo to include an upload function,
> but I am failing. Could someone can show me how to do this? I have tried to
> add this code, but it does not work. [Orignal Demo]
> https://github.com/Werkov/PyQt4/blob/master/examples/network/ftp/ftp.py
>
> buttonBox.addButton(self.uploadButton,
>             QtGui.QDialogButtonBox.ActionRole)
> self.uploadButton = QtGui.QPushButton("upload")
>
> self.uploadButton.clicked.connect(self.selectFile)def selectFile(self):
>
>     self.filename =QtGui.QFileDialog.getOpenFileName()
>     up_fname = re.sub(r".*/","",self.filename)
>     upload_file = QtCore.QFile(self.filename)
>     self.ftp.put(upload_file, up_fname)
>
> _______________________________________________ PyQt mailing list
> PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140701/16d7a8e4/attachment.html>


More information about the PyQt mailing list