def main(): print "Test-directory_parser" files = parseListing(_EXAMPLE) for i in files: print i.toString() print "Borked example" try: files = parseListing(BORKED_EXAMPLE) for i in files: print i.toString() except Exception, ex: print "Exception!" print str(ex)
def listFiles(self): if self.machine.getState() != STATE_LOGGED: self.warn("Expecting STATE_LOGGED") # todo: polish according to retrieveFile suc = self.machine.pasv() if not suc: return None dataSocket = self.machine.getDataSocket() ## INJECTION # The transaction may go well (reponse code is OK) but the # returned IP address and port may not be readable. if not self.PASV_RESPONSE_READ_BUG: if dataSocket is None: self.machine.dataConnectionClearAfterError() return None else: self.warn("PASV_RESPONSE_READ_BUG is active") suc = self.dataNet.connect(dataSocket.hostname, dataSocket.port) if not suc: self.machine.dataConnectionClearAfterError() return None dataReader = self.dataNet.createNetworkReader() self.machine.dataConnectionEstablished() suc = self.machine.listing() if suc: data = dataReader.readAll() suc2 = self.machine.transferSuccessfullyDone() if not suc2: self.machine.dataConnectionClearAfterError() return None return parseListing(data) else: self.machine.dataConnectionClearAfterError() return None