1

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

12
  • try this code; replace sftp.get with sftp.put to upload instead of downloading. Commented Mar 28, 2014 at 9:46
  • With sftp.put the terminal says that: IOError: [Errno 2] No such file Commented Mar 28, 2014 at 10:01
  • you also need to replace sftp.listdir() with os.listdir('.') because you are copying local files to remote directory therefore you need to list local paths Commented Mar 28, 2014 at 10:06
  • 1
    Huhh... paramiko bug with big files... see here Damage ! Commented Mar 28, 2014 at 10:52
  • does this fabric-based solution also fail? (it is based on paramiko so it should fail) Commented Mar 28, 2014 at 10:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.