DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG� RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=35260>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND� INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=35260 Summary: FTPClient.retrieveFile() results in 0 byte files Product: Commons Version: 1.4 Final Platform: HP OS/Version: HP-UX Status: NEW Severity: major Priority: P2 Component: Net AssignedTo: [email protected] ReportedBy: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] FTPClient's retrieveFile() always returns false and results in 0 byte files FTPClient's completePendingCommand() always never returns when uncommented out Attempted client on Win2000 and Server on HPUX 11(?), also client and server both on HPUX. /lib contains commons-net-1.4.0.jar and jakarta-oro-2.0.8.jar. Thanks, Steve Relative Source Code: import org.apache.commons.net.ftp.*; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintWriter; import java.rmi.dgc.VMID; import java.text.DateFormat; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Date; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; private void get(Calendar criteriaDateTime) throws Exception { FTPClient ftp = null; FTPFile[] serverFiles = null; boolean isLoggedIn = false; Exception exception = null; Date serverFileDate; try { // Connect and logon to FTP Server ftp = new FTPClient(); ftp.connect(server); isLoggedIn = ftp.login(userId, password); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())){ throw new Exception("FTP server refused connection."); } Logger.log("ftp post-login reply: " + ftp.getReplyString ()); // Use passive mode assuming we are behind a firewall. ftp.enterLocalPassiveMode(); // default to binary transfer ftp.setFileType(FTP.BINARY_FILE_TYPE); Logger.log("ftp status: " + ftp.getStatus()); // get list of files in FTP server directory FTPListParseEngine engine = ftp.initiateListParsing (serverDirectory); if(engine.hasNext()) { serverFiles = engine.getFiles(); Logger.log("Number of files in server directory: " + serverFiles.length); // what if the file is removed by another process? for (int i = 0; i < serverFiles.length; i++) { if(serverFiles[i].isFile()){ serverFileDate = serverFiles [i].getTimestamp().getTime(); // select files form the server if file attributes have not changed in x seconds if (serverFileDate.compareTo (criteriaDateTime.getTime()) <= 0) { if(isZipClientFile){ doFtpZip(ftp, serverFiles[i]); } else{ doFtpOnly(ftp, serverFiles[i]); } // delete server file if requested if(isDeleteServerFile){ ftp.deleteFile (serverFiles[i].getName()); } } } } } } catch (Exception e) { Logger.handleError(this.getClass().getName(), "get", e); exception = e; } finally{ // Logout and disconnect from the FTP Server if(ftp != null){ if(isLoggedIn) ftp.logout(); if(ftp.isConnected()) ftp.disconnect(); } } if(exception != null){ throw exception; } } private void doFtpOnly(FTPClient ftp, FTPFile serverFile) throws Exception { DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); int count; byte data[] = new byte[BUFFER]; FileOutputStream fos = null; Exception exception = null; try{ Logger.log("FTP Download: " + serverFile.getName() + " with timestamp " + df.format(serverFile.getTimestamp ().getTime())); fos = new FileOutputStream( clientDirectory + File.separator + serverFile.getName()); // stream the ftp contents into an inputstream // this always returns false if(!ftp.retrieveFile(serverFile.getName(), fos)){ // throw new Exception("false return from ftp.retrieveFile()"); Logger.log("false return from ftp.retrieveFile ()"); } /* this command freezes every time when running on Windows */ Logger.log("to ftp.completePendingCommand()"); if(!ftp.completePendingCommand()){ throw new Exception("completePendingCommand() returned false"); } Logger.log("did ftp.completePendingCommand()"); } catch(Exception e){ Logger.handleError(this.getClass().getName(), "doFtpOnly", e); exception = e; } finally{ // close input stream if(fos != null) fos.close(); Logger.log("FTP end"); } if(exception != null){ throw exception; } } -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
