From: Albert A. <ap...@em...> - 2005-11-02 08:50:52
|
I ran into the following problems with FtpScanner: - if includeSubfolder=3Dtrue the scanner only walked down the first=20 line of the directory tree - I noticed a permanent connect/disconnect activity (> 1/sec)=20 despite the period property was set to 60000ms The included patch (diff against 1.24) fixes these problems and - adds an additional property maxDepth that you can use to limit=20 the number of levels that the scanner walks down the directory tree=20 (beginning from ftpFolder). The default value for maxDepth, if omitted, is 0 which is=20 equivalent to setting includeSubfolders=3Dfalse. ciao apa *** FtpScanner.java Mon Oct 31 11:27:07 2005 --- modules/scanner/src/com/babeldoc/scanner/worker/FtpScanner.java Mon Oct= 31 10:52:36 2005 *************** *** 110,113 **** --- 110,114 ---- public static final String SCAN_SUBFOLDERS =3D "includeSubfolders"; public static final String FILTER_FILENAME =3D "filter"; + public static final String MAX_DEPTH =3D "maxDepth"; =20=20 //private final static int rertyCount =3D 3; *************** *** 118,122 **** private String ftpPassword =3D ""; private String ftpUsername =3D ""; ! private int ftpFileType =3D FTPClient.ASCII_FILE_TYPE; private String localBackupFolder =3D ""; private boolean scanSubfolders =3D false; --- 119,125 ---- private String ftpPassword =3D ""; private String ftpUsername =3D ""; ! private int ftpFileType =3D FTPClient.ASCII_FILE_TYPE; ! private int maxDepth =3D 0; ! private int curDepth =3D 0; private String localBackupFolder =3D ""; private boolean scanSubfolders =3D false; *************** *** 191,194 **** --- 194,198 ---- .equalsIgnoreCase(this.getInfo().getStrValue(SCAN_SUBFOLDERS)))) { scanSubfolders =3D true; + maxDepth =3D Integer.parseInt(this.getInfo().getStrValue(MAX_DEPTH)); } =20=20 *************** *** 238,249 **** if (ftpClient.login(ftpUsername, ftpPassword)) { if (ftpClient.changeWorkingDirectory(ftpFolder)) { ! if(ftpClient.setFileType(ftpFileType)) { ! // ! } else { ! ftpClient.disconnect(); ! throw new ScannerException( ! I18n.get("scanner.FtpScanner.error.filetype")); ! } ! } else { ftpClient.disconnect(); throw new ScannerException( --- 242,253 ---- if (ftpClient.login(ftpUsername, ftpPassword)) { if (ftpClient.changeWorkingDirectory(ftpFolder)) { ! if(ftpClient.setFileType(ftpFileType)) { ! // ! } else { ! ftpClient.disconnect(); ! throw new ScannerException( ! I18n.get("scanner.FtpScanner.error.filetype")); ! } ! } else { ftpClient.disconnect(); throw new ScannerException( *************** *** 462,474 **** log.logDebug("Scanning " + ftpClient.printWorkingDirectory()); } !=20 ! if ((ftpClient.getReplyCode() =3D=3D FTPReply.CLOSING_DATA_CONNECTION) ! || (ftpClient.getReplyCode() =3D=3D FTPReply.SERVICE_NOT_AVAILABLE)) { ! ftpClient.disconnect(); ! connectToHost(); ! } =20=20 //first change working dir! ftpClient.changeWorkingDirectory(folder); =20=20 FTPFile[] ftpFiles =3D null; --- 466,481 ---- log.logDebug("Scanning " + ftpClient.printWorkingDirectory()); } !=20=09=09=09 ! /* the following code creates unnecessary reconnects - if you think it= is necessary uncoment it ! * if ((ftpClient.getReplyCode() =3D=3D FTPReply.CLOSING_DATA_CONNECTI= ON) ! * || (ftpClient.getReplyCode() =3D=3D FTPReply.SERVICE_NOT_AVAILABLE))= { ! * //ftpClient.disconnect(); ! * //connectToHost(); ! * } ! */ =20=20 //first change working dir! ftpClient.changeWorkingDirectory(folder); + curDepth++; =20=20 FTPFile[] ftpFiles =3D null; *************** *** 499,502 **** --- 506,512 ---- =20=20 if (ftpFiles =3D=3D null) { + // no files found in this dir - so return to parent + ftpClient.changeWorkingDirectory( ".." ); + curDepth--; return; } *************** *** 515,521 **** } else if (ftpFiles[i].isDirectory() && scanSubfolders) { //Get files from new current diretory by executing this method recur= s. ! processFtpFolder(ftpFiles[i].getName()); } } } catch (Exception e) { throw new ScannerException( --- 525,539 ---- } else if (ftpFiles[i].isDirectory() && scanSubfolders) { //Get files from new current diretory by executing this method recur= s. ! if (curDepth <=3D maxDepth){ ! //Walk down the tree until max depth limit is reached ! processFtpFolder(ftpFiles[i].getName()); ! } } } + // return to parent, otherwise you get stuck at the end of the first b= ranch + // when walking down subdirs + ftpClient.changeWorkingDirectory( ".." ); + curDepth--; +=20 } catch (Exception e) { throw new ScannerException( *************** *** 618,622 **** --- 636,649 ---- I18n.get("scanner.FtpScannerInfo.option.filter"))); =20=20 + options.add( + new ConfigOption( + FtpScanner.MAX_DEPTH, + IConfigOptionType.STRING, + "0", + false, + "scanner.FtpScannerInfo.option.maxDepth")); +=20 return options; } } +=20 --=20 ___________________________________________________ Play 100s of games for FREE! http://games.mail.com/ |