diff --git a/src/borgstore/backends/sftp.py b/src/borgstore/backends/sftp.py index 2fbbd82..54c11f8 100644 --- a/src/borgstore/backends/sftp.py +++ b/src/borgstore/backends/sftp.py @@ -41,11 +41,12 @@ def _connect(self): ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) config_path = Path("~/.ssh/config").expanduser() - if config_path.exists(): + try: sc = paramiko.SSHConfig.from_path(str(config_path)) - scd = sc.lookup(self.hostname) - else: + except FileNotFoundError: scd = paramiko.SSHConfigDict() # empty dict + else: + scd = sc.lookup(self.hostname) ssh.connect( hostname=scd.get("hostname", self.hostname), username=scd.get("user", self.username),