Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73777

How to add ftp put function in PyQT network ftp demo

Newsgroups comp.lang.python
Date 2014-07-01 03:27 -0700
Message-ID <7492d8ec-8e64-4f0d-b927-b3981b75eea2@googlegroups.com> (permalink)
Subject How to add ftp put function in PyQT network ftp demo
From 不坏阿峰 <onlydebian@gmail.com>

Show all headers | View raw


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

at First, i add these code into demo. not work at all
##############
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)

##############

Second, i modify like this, i can upload small file successfully, but fail on big size file, the app will crash.

#####################
    def selectFile(self):
        self.filename =QtGui.QFileDialog.getOpenFileName()
        print self.filename
        up_fname = re.sub(r".*/","",self.filename)
        print up_fname


        upload_file = QtCore.QFile(self.filename)
        #print upload_file
        upload_file.open(QtCore.QIODevice.ReadOnly)
        ba = QtCore.QByteArray()
        ba.append(upload_file.readAll())
        
        #buffer = QtCore.QBuffer()            #### do not how to use Buffer
        #buffer.open(QtCore.QIODevice.ReadWrite)
        #buffer.setData(ba)
        
        self.ftp.put(ba, up_fname)
        self.progressDialog.setLabelText("Uploading %s..." % up_fname)
        self.uploadButton.setEnabled(False)
        self.progressDialog.exec_()
        self.uploadButton.setEnabled(True)
        self.ftp.list()

####################

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

How to add ftp put function in PyQT network ftp demo 不坏阿峰 <onlydebian@gmail.com> - 2014-07-01 03:27 -0700
  Re: How to add ftp put function in PyQT network ftp demo 不坏阿峰 <onlydebian@gmail.com> - 2014-07-02 01:05 -0700

csiph-web