Browse Source

fix ssh and telnet connection scripts. Related to ftth#40

Guillermo Espinoza 6 năm trước cách đây
mục cha
commit
12b991fe6d
2 tập tin đã thay đổi với 16 bổ sung8 xóa
  1. 2 1
      ObjectSsh.py
  2. 14 7
      ObjectTelnet.py

+ 2 - 1
ObjectSsh.py

@@ -120,7 +120,8 @@ class ObjectSsh(ObjectConnection):
         :param expected: Expected string to stop listening
         """
         self.command_print(command)
-        if "\\n" in command and len(command) == 4:
+        command = command.strip()
+        if "\\n" in command and (len(command) == 4 or len(command) == 2):
             print "Sendig ENTER \\r\\n"
             command = '\r\n'
         else:

+ 14 - 7
ObjectTelnet.py

@@ -152,14 +152,21 @@ class ObjectTelnet(ObjectConnection):
         :param command:
         :param expected: Expected string to stop listening
         """
+        self.command_print(command)
         command = command.strip()
-        if not (command[:-1] == self.NEW_LINE_UNIX or command[:-2] == self.NEW_LINE_WINDOWS):
-            self.command_print(command)
-            if not self.command_enable(command) and not self.command_quit(command):
-                command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
-                if command.__len__() > 0:
-                    self.tn.write(command + self.NEW_LINE_UNIX)
-                    self.read_data([expected])
+        if "\\n" in command and (len(command) == 4 or len(command) == 2):
+            print "Sendig ENTER \\r\\n"
+            command = '\r\n'
+        else:
+            command = command.rstrip(self.NEW_LINE_WINDOWS).rstrip(self.NEW_LINE_UNIX)
+        if not self.command_enable(command) and not self.command_quit(command):
+            if command.__len__() > 0:
+                if self.debug:
+                    print "Send: "
+                    print command
+                self.stdin.write(command + self.NEW_LINE_UNIX)
+                self.stdin.flush()
+                self.read_data(expected)
 
     def read_data(self, expected):
         """