2

pysftp's get() method sometime hangs.

For example if I execute the following to download a file:

import pysftp #pip install sftp
import sys

hostname = "128.65.45.12"
username = "bob"       
password = "123456"  

sftp = pysftp.Connection(hostname, username=username, password=password)
while True:
    sftp.get('/data/word_vectors/GoogleNews-vectors-negative300.txt', preserve_mtime=True)
    print('done')

It may display a few "done", i.e. download the file a few times, but then hangs for ever (while the server is still responsive). How can I set a timeout for pysftps' get() to restart it if it hangs?

Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
  • `signal.alarm()` may do the trick as demonstrated in the python docs [signal example](https://docs.python.org/3.5/library/signal.html#example). I don't have `pysftp` so haven't tested it. – tdelaney Dec 19 '15 at 01:31

0 Answers0