Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var response = '', // FTP LIST response as a string
- lines = response.trim().split("\r\n"),
- parsed = [],
- regexp = new RegExp(
- '^([\\-dbclps])' + // Directory flag [1]
- '([\\-rwxs]{9})\\s+' + // Permissions [2]
- '(\\d+)\\s+' + // Number of items [3]
- '(\\w+)\\s+' + // File owner [4]
- '(\\w+)\\s+' + // File group [5]
- '(\\d+)\\s+' + // File size in bytes [6]
- '(\\w{3}\\s+\\d{1,2}\\s+' + // 3-char month and 1/2-char day of the month [7]
- '(?:\\d{1,2}:\\d{1,2}|\\d{4}))' + // Time or year (need to check conditions) [+= 7]
- '\\s+(.+)$' // File/directory name [8]
- );
- // Add each parsed line to the parsed array
- for(var line in lines){
- var parsedLine = regexp.exec(lines[line]);
- if(parsedLine === null) {
- continue; // Skip if no match
- } else {
- parsed[line] = {
- type: parsedLine[1],
- perms: parsedLine[2],
- items: parsedLine[3],
- owner: parsedLine[4],
- group: parsedLine[5],
- size: parsedLine[6],
- date: parsedLine[7],
- file: parsedLine[8],
- };
- }
- }
- alert(JSON.stringify(parsed));
Add Comment
Please, Sign In to add comment