diff --git a/tsshbatch.py b/tsshbatch.py index c68f39b..dca4f96 100755 --- a/tsshbatch.py +++ b/tsshbatch.py @@ -20,7 +20,7 @@ CMDINCL = PROGENV + "CMDS" HOSTINCL = PROGENV + "HOSTS" -CVSID = "$Id: tsshbatch.py,v 1.221 2016/01/16 19:47:18 tundra Exp $" +CVSID = "$Id: tsshbatch.py,v 1.222 2016/01/16 20:04:48 tundra Exp $" VERSION = CVSID.split()[2] CPRT = "(c)" PROGDATE = "2011-2016" @@ -247,24 +247,6 @@ # End of 'ConditionLine()' -##### -# Setup An SSH Connect -##### - -def ConnectSSH(host, user, pw, time): - - ssh = paramiko.SSHClient() - ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - - if KEYEXCHANGE: - ssh.connect(host, username=user, timeout=time) - else: - ssh.connect(host, username=user, password=pw, allow_agent=False, look_for_keys=False, timeout=time) - - return ssh - -# End of 'ConnectSSH()' - ##### # Check To See If A Key Exists In A String, Excluding Quoted Substrings @@ -367,7 +349,7 @@ # Get an sftp connection and move files try: - ssh = ConnectSSH(host, user, pw, TIMEOUT) + ssh = SSHConnect(host, user, pw, TIMEOUT) sftp = ssh.open_sftp() for src in filelist: @@ -448,7 +430,7 @@ # Connect and run the command, reporting results as we go try: - ssh = ConnectSSH(host, user, pw, TIMEOUT) + ssh = SSHConnect(host, user, pw, TIMEOUT) if NOISELEVEL != QUIET: PrintReport([host, CONSUCCESS], FORMAT=Format) @@ -695,6 +677,25 @@ ##### +# Setup An SSH Connection +##### + +def SSHConnect(host, user, pw, time): + + ssh = paramiko.SSHClient() + ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + + if KEYEXCHANGE: + ssh.connect(host, username=user, timeout=time) + else: + ssh.connect(host, username=user, password=pw, allow_agent=False, look_for_keys=False, timeout=time) + + return ssh + +# End of 'SSHConnect()' + + +##### # Search A Path For A File, Returning First Match #####