Skip to content

Commit

Permalink
Separate try loops for ssh and scp
Browse files Browse the repository at this point in the history
  • Loading branch information
Trygve Aspenes committed Aug 6, 2018
1 parent 2d0857c commit 6ec79ca
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions trollmoves/server.py
Expand Up @@ -648,17 +648,26 @@ def copy(self):
from paramiko import SSHClient
from scp import SCPClient

ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect(self.destination.hostname,
username=self.destination.username)

try:
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect(self.destination.hostname,
username=self.destination.username)
except Exception as e:
raise

LOGGER.debug('hostname %s', self.destination.hostname)
LOGGER.debug('dest path %s ', os.path.dirname(self.destination.path))
LOGGER.debug('origin %s ', self.origin)

try:
scp = SCPClient(ssh.get_transport())
except Exception as e:
LOGGER.error("Failed to initiate SCPClient: " +str(e))
ssh.close()
raise

try:
scp.put(self.origin, self.destination.path)
except Exception as e:
LOGGER.error("Something went wrong with scp: " + str(e))
Expand Down

0 comments on commit 6ec79ca

Please sign in to comment.