python paramiko module error with callback

2019-03-02 18:45发布

I'm trying to use the paramiko module to copy a (big) file in my local network, and get the output to display a GtkProgressBar. A part of my code is:

    ...
        NetworkCopy.pbar.set_text("Copy of the file in the Pi...")
        while gtk.events_pending():            # refresh the progress bar
              gtk.main_iteration()   

        self.connection(transferred, toBeTransferred)

  def connection(self, transferred, toBeTransferred):

        sftp = self.sftp
        fichier_pc = self.fichier_pc
        chemin_pi = self.chemin_pi             # var names are in french !
        fichier = self.fichier
        transferred = self.transferred
        toBeTransferred = self.toBeTransferred
        print "Transferred: {0}\tStill to send: {1}".format(transferred, toBeTransferred)
        sftp.put(fichier_pc, chemin_pi + fichier, callback=self.connection)

In the terminal, I can see

Transferred: 0  Still to send: 3762398252

for a while, but after 10s I have this error:

  File "network_copier.py", line 158, in connection
    sftp.put(fichier_pc, chemin_pi + fichier, callback=self.connection)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 615, in put
    return self.putfo(fl, remotepath, os.stat(localpath).st_size, callback, confirm)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 577, in putfo
    fr.close()
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_file.py", line 67, in close
    self._close(async=False)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_file.py", line 88, in _close
    self.sftp._request(CMD_CLOSE, self.handle)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 689, in _request
    return self._read_response(num)
  File "/usr/lib/python2.7/dist-packages/paramiko/sftp_client.py", line 721, in _read_response
    raise SSHException('Server connection dropped: %s' % (str(e),))
paramiko.SSHException: Server connection dropped: 

I have the 1.12.2 version of paramiko, from this ppa

Thanks for your help

Edit: The solution is to use pexpect instead of paramiko. It's working with big files. See here

0条回答
登录 后发表回答