Skip to content

Commit

Permalink
Remove unneeded try/except in sftp uploader
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Aug 29, 2018
1 parent 3c6b504 commit 71125a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '18.8.0'
_release = '1603'
_commit = '3e5b182'
_release = '1604'
_commit = '3c6b504'
31 changes: 14 additions & 17 deletions src/pywws/service/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,20 @@ def __init__(self, context, check_params=True):
def session(self):
logger.info("Uploading to web site with SFTP")
address = (self.params['site'], self.params['port'])
try:
with paramiko.Transport(address) as transport:
transport.start_client(timeout=30)
if self.params['privkey']:
transport.auth_publickey(
username=self.params['user'],
key=paramiko.RSAKey.from_private_key_file(
self.params['privkey']))
else:
transport.auth_password(
username=self.params['user'],
password=self.params['password'])
with paramiko.SFTPClient.from_transport(transport) as session:
session.chdir(self.params['directory'])
yield session
except Exception as ex:
logger.exception(ex)
with paramiko.Transport(address) as transport:
transport.start_client(timeout=30)
if self.params['privkey']:
transport.auth_publickey(
username=self.params['user'],
key=paramiko.RSAKey.from_private_key_file(
self.params['privkey']))
else:
transport.auth_password(
username=self.params['user'],
password=self.params['password'])
with paramiko.SFTPClient.from_transport(transport) as session:
session.chdir(self.params['directory'])
yield session

def upload_file(self, session, path):
target = os.path.basename(path)
Expand Down

0 comments on commit 71125a9

Please sign in to comment.