From: McDonald, B. <Bru...@ba...> - 2005-11-04 21:18:20
|
Do it. -----Original Message----- From: bab...@li... [mailto:bab...@li...] On Behalf Of Michael Ansley Sent: Friday, November 04, 2005 4:05 PM To: bab...@li... Subject: Re: [Babeldoc-devel] FtpScanner fixes 2 Has somebody applied this patch? Can I apply it? And the previous one? On Friday 04 November 2005 15:21, Albert Apolloner wrote: > New diff against v1.24. > Fixes problem with FTP server timeouts, > directory tree iteration (see previous msg) > > ciao > apa > > *** FtpScanner.java Mon Oct 31 11:27:07 2005 > --- modules/scanner/src/com/babeldoc/scanner/worker/FtpScanner.java Fri Nov > 4 10:29:31 2005 *************** > *** 81,84 **** > --- 81,85 ---- > import org.apache.commons.net.ftp.FTPFileListParser; > import org.apache.commons.net.ftp.FTPReply; > + import org.apache.commons.net.ftp.FTPConnectionClosedException; > > import com.babeldoc.core.I18n; > *************** > *** 110,113 **** > --- 111,115 ---- > public static final String SCAN_SUBFOLDERS = "includeSubfolders"; > public static final String FILTER_FILENAME = "filter"; > + public static final String MAX_DEPTH = "maxDepth"; > > //private final static int rertyCount = 3; > *************** > *** 118,122 **** > private String ftpPassword = ""; > private String ftpUsername = ""; > ! private int ftpFileType = FTPClient.ASCII_FILE_TYPE; > private String localBackupFolder = ""; > private boolean scanSubfolders = false; > --- 120,126 ---- > private String ftpPassword = ""; > private String ftpUsername = ""; > ! private int ftpFileType = FTPClient.ASCII_FILE_TYPE; > ! private int maxDepth = 0; > ! private int curDepth = 0; > private String localBackupFolder = ""; > private boolean scanSubfolders = false; > *************** > *** 166,176 **** > */ > public void doScan() throws ScannerException { > try { > ! processFtpFolder(ftpFolder); > } catch (Exception e) { > ! throw new ScannerException( > I18n.get("scanner.FtpScanner.error.general"), > e); > ! } > } > > --- 170,199 ---- > */ > public void doScan() throws ScannerException { > + boolean err = false; > try { > ! processFtpFolder(ftpFolder); > ! } catch (FTPConnectionClosedException cl){ > ! err = true; > ! if(log.isDebugEnabled()) > ! log.logDebug("Connection to FTP server was terminated"); > } catch (Exception e) { > ! err = true; > ! throw new ScannerException( > I18n.get("scanner.FtpScanner.error.general"), > e); > ! } finally { > ! try { > ! if (err){ > ! if(log.isDebugEnabled()) > ! log.logDebug("Need to reconnect before scanning ..."); > ! > ! ftpClient.disconnect(); > ! connectToHost(); > ! processFtpFolder(ftpFolder); > ! } > ! }catch (Exception re){ > ! throw new ScannerException("Reconnection to > FTPServer failed"); ! } > ! } > } > > *************** > *** 191,194 **** > --- 214,218 ---- > .equalsIgnoreCase(this.getInfo().getStrValue(SCAN_SUBFOLDERS)))) { > scanSubfolders = true; > + maxDepth = Integer.parseInt(this.getInfo().getStrValue(MAX_DEPTH)); > } > > *************** > *** 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( > --- 262,273 ---- > 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( > *************** > *** 347,352 **** > > if ((ftpOutFolder != null) && (!ftpOutFolder.equals(""))) { > ! String ftpOutPath = > ! ftpOutFolder + fileName.substring(ftpFolder.length()); > ftpClient.rename(fileName, ftpOutPath); > } > --- 371,387 ---- > > if ((ftpOutFolder != null) && (!ftpOutFolder.equals(""))) { > ! StringBuffer sbOutPath = new > StringBuffer(); ! if > (ftpOutFolder.endsWith("/")){ ! > sbOutPath.append( > ! ftpOutFolder + fileName.substring(fileName.indexOf(scanFileName)) > ! ); > ! }else{ > ! sbOutPath.append( > ! ftpOutFolder + "/" > ! + > fileName.substring(fileName.indexOf(scanFileName)) ! > ); > ! } > ! String ftpOutPath = sbOutPath.toString(); > ! > ftpClient.rename(fileName, ftpOutPath); > } > *************** > *** 375,379 **** > * @throws ScannerException > */ > ! private void processFtpFolder(String folder) throws ScannerException { > //This is inner class that implements FileListParser interface > //It is used for parsing files returned from MS ftp server > --- 410,414 ---- > * @throws ScannerException > */ > ! private void processFtpFolder(String folder) throws ScannerException, > FTPConnectionClosedException { //This is inner class that implements > FileListParser interface //It is used for parsing files returned from MS > ftp server > *************** > *** 462,474 **** > log.logDebug("Scanning " + ftpClient.printWorkingDirectory()); > } > ! > ! if ((ftpClient.getReplyCode() == FTPReply.CLOSING_DATA_CONNECTION) > ! || (ftpClient.getReplyCode() == FTPReply.SERVICE_NOT_AVAILABLE)) { > ! ftpClient.disconnect(); > ! connectToHost(); > ! } > ! > //first change working dir! > ftpClient.changeWorkingDirectory(folder); > > FTPFile[] ftpFiles = null; > --- 497,504 ---- > log.logDebug("Scanning " + ftpClient.printWorkingDirectory()); > } > ! > //first change working dir! > ftpClient.changeWorkingDirectory(folder); > + curDepth++; > > FTPFile[] ftpFiles = null; > *************** > *** 499,502 **** > --- 529,535 ---- > > if (ftpFiles == null) { > + // no files found in this dir - so return to parent > + ftpClient.changeToParentDirectory(); > + curDepth--; > return; > } > *************** > *** 515,521 **** > } else if (ftpFiles[i].isDirectory() && scanSubfolders) { > //Get files from new current diretory by executing this method > recurs. ! processFtpFolder(ftpFiles[i].getName()); > } > } > } catch (Exception e) { > throw new ScannerException( > --- 548,564 ---- > } else if (ftpFiles[i].isDirectory() && scanSubfolders) { > //Get files from new current diretory by executing this method > recurs. ! if (curDepth <= 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 > branch + // when walking down subdirs > + ftpClient.changeToParentDirectory(); > + curDepth--; > + } catch (FTPConnectionClosedException ce) { > + // The FTP Server has probably terminated the > connection due to some timeout + throw new > FTPConnectionClosedException("Oops, disconnected!"); } catch (Exception e) > { > throw new ScannerException( > *************** > *** 618,622 **** > --- 661,674 ---- > I18n.get("scanner.FtpScannerInfo.option.filter"))); > > + options.add( > + new ConfigOption( > + FtpScanner.MAX_DEPTH, > + IConfigOptionType.STRING, > + "0", > + false, > + "scanner.FtpScannerInfo.option.maxDepth")); > + > return options; > } > } > + ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php _______________________________________________ Babeldoc-devel mailing list Bab...@li... https://lists.sourceforge.net/lists/listinfo/babeldoc-devel |