Skip to content

Commit

Permalink
Merge pull request #13 from TAlonglong/improve-error-handling-scp-mover
Browse files Browse the repository at this point in the history
Improve error handling in SCPMover
  • Loading branch information
mraspaud committed Jan 21, 2019
2 parents b87baf3 + 6ec79ca commit d5de9ee
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions trollmoves/server.py
Expand Up @@ -648,20 +648,32 @@ 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)

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

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


class SftpMover(Mover):
Expand Down

0 comments on commit d5de9ee

Please sign in to comment.