Ejemplo n.º 1
0
        def action():
            if mapped:
                path = file_path
            else:
                path = self._getMappedPath(file_path)

            path = self.__encode(path)

            if self.config['debug_extras']['debug_remote_paths']:
                print ("FTPSync <debug> list path " + file_path + " => " + str(path))

            contents = []
            result = []

            try:
                self.retryingCommand('retrlines', ["LIST -a " + path, lambda data: contents.append(data)])
            except Exception as e:
                if self.__isErrorCode(e, ['ok', 'passive']) or str(e).find(ftpErrors['typeIsNow']) != -1:
                    self.retryingCommand('retrlines', ["LIST -a " + path, lambda data: contents.append(data)])
                elif str(e).find('No such file'):
                    raise FileNotFoundException
                else:
                    try:
                        self.retryingCommand('dir', [path, lambda data: contents.append(data)])
                    except Exception as e:
                        if self.__isErrorCode(e, ['ok', 'passive']) or str(e).find(ftpErrors['typeIsNow']) != -1:
                            self.retryingCommand('retrlines', ["LIST -a " + path, lambda data: contents.append(data)])
                        elif str(e).find('No such file'):
                            raise FileNotFoundException
                        else:
                            raise

            for content in contents:
                try:
                    if self.config['debug_extras']['print_list_result'] is True:
                        print ("FTPSync <debug> LIST line: " + Types.u(content))
                except KeyError:
                    pass

                split = re_ftpListParse.search(content)

                if split is None:
                    continue

                isDir = split.group(1) == 'd'
                permissions = split.group(2)
                filesize = split.group(3)
                lastModified = split.group(4)
                name = split.group(5)

                if all is True or (name != "." and name != ".."):
                    data = Metafile(name, isDir, self.__parseTime(lastModified) + int(self.config['time_offset']), filesize, os.path.normpath(path).replace('\\', '/'), permissions)
                    result.append(data)

            return result
	def __commandName(self, command):
		return Types.u(command.__class__.__name__)