I have a python script connecting sftp to a raspberry pi. It works fine but I'm a bit surprised. I'm testing the script. If I change portnr from let us say 1001 as given to 1002 the script will not stop trying until I Ctrl + C. Below follows part of my code. I thought except took care of any errors and sys.exit() but apparently it does not. Is there a way to terminate/exit the script if trying fails?
Code:
ftpHost = 'pi4.local'sftpPort = '1001'uname = 'jeff'privkeyPath = '/home/jeff/.ssh/id_ed25519'try: with sftpretty.Connection( host=sftpHost, port=sftpPort, username=uname, private_key=privkeyPath ) as sftp: sftp.get('/home/jeff/usb1/ips/test.txt','/home/jeff/usb/ips/test.txt')except: print("Something went wrong") sys.exit()else: print("All ok.") Statistics: Posted by imsdal70 — Sun Aug 10, 2025 5:50 pm