Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions bots/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ def connect(self):
class sftp(_comsession):
''' SFTP: SSH File Transfer Protocol (SFTP is not FTP run over SSH, SFTP is not Simple File Transfer Protocol)
standard port to connect to is port 22.
requires paramiko and pycrypto to be installed
requires paramiko to be installed
based on class ftp and ftps above with code from demo_sftp.py which is included with paramiko
Mike Griffin 16/10/2010
Henk-jan ebbers 20110802: when testing I found that the transport also needs to be closed. So changed transport ->self.transport, and close this in disconnect
Expand All @@ -1373,8 +1373,10 @@ class sftp(_comsession):
def connect(self):
try:
import paramiko
except:
raise ImportError('Dependency failure: communicationtype "sftp" requires python library "paramiko".')
if paramiko.__version__ < '2.0':
raise ImportError('Dependency failure: communicationtype "sftp" requires python library "paramiko" version 2.0 or higher (version %s installed)' %paramiko.__version__)
except ImportError:
raise ImportError('Dependency failure: communicationtype "sftp" requires python library "paramiko" version 2.0 or higher.')
# setup logging if required
ftpdebug = botsglobal.ini.getint('settings','ftpdebug',0)
if ftpdebug > 0:
Expand All @@ -1389,6 +1391,9 @@ def connect(self):
except:
port = 22 # default port for sftp

#if password is empty string: use None. Else error can occur.
secret = self.channeldict['secret'] or None

if self.userscript and hasattr(self.userscript,'hostkey'):
hostkey = botslib.runscript(self.userscript,self.scriptname,'hostkey',channeldict=self.channeldict)
else:
Expand All @@ -1399,13 +1404,13 @@ def connect(self):
pkey = paramiko.RSAKey.from_private_key_file(filename=privatekeyfile,password=pkeypassword)
else:
pkey = paramiko.DSSKey.from_private_key_file(filename=privatekeyfile,password=pkeypassword)
# RSA private key (keyfile) and optional passphrase (secret) in channel without user script
elif self.channeldict['keyfile']:
pkey = paramiko.RSAKey.from_private_key_file(filename=self.channeldict['keyfile'],password=secret)
secret = None
else:
pkey = None

if self.channeldict['secret']: #if password is empty string: use None. Else error can occur.
secret = self.channeldict['secret']
else:
secret = None
# now, connect and use paramiko Transport to negotiate SSH2 across the connection
self.transport = paramiko.Transport((hostname,port))
self.transport.connect(username=self.channeldict['username'],password=secret,hostkey=hostkey,pkey=pkey)
Expand Down