0

On this part of python script below, I want to use a sftp.put() in a separate thread/processus and kill it after a while, all in the same script. I don’t know how to write this using Thread or multiprocessing.

Is someone may show me a simple way to do it please?

Ubuntu 18.04, paramiko 2.6.0

[...]
raspi = paramiko.SSHClient()
raspi.set_missing_host_key_policy(paramiko.AutoAddPolicy())
raspi.connect(ip , username= "", password= "" , timeout=10)
sftp = raspi.open_sftp()        

[...]   

sftp.put(source, destination , callback=None, confirm=True)  

raspi.close()

[...]

Update 1

Ok, so this code is working, but if I use all the arguments of the sftp.put(), he doesn't work and return a syntax error:

 [...]
    raspi = paramiko.SSHClient()
    raspi.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    raspi.connect(ip , username= "", password= "" , timeout=10)
    sftp = raspi.open_sftp()        

    [...]   

    th = threading.Thread(target=sftp.put, args=(source, destination))
    th.start()
    th.join()

    raspi.close()

    [...]

Don't work with (invalid syntax):

th = threading.Thread(target=sftp.put, args=(source, destination, callback=None, confirm=True))
pierre
  • 11
  • 3
  • 1
    Please try solving this using either threads or multiprocessing and then show what you tried and how it doesn't work – Metareven Nov 15 '19 at 13:55
  • ok thanks, in update 1 this seems to work but not when I use all the arguments. – pierre Nov 15 '19 at 16:51
  • Can you post the stacktrace? Where does source and destination come from? I cannot see it in your code anywhere. Also what sftp-library are you using? I cannot see any imports in your example code. Also callback and confirm should be in kwargs and not args – Metareven Nov 17 '19 at 12:48
  • It seems that you have resolved this: https://stackoverflow.com/q/58844902/850848#58890159 - So if you know the answer, please post it here. – Martin Prikryl Nov 18 '19 at 13:25

0 Answers0