[ 
https://issues.apache.org/jira/browse/NET-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12528387
 ] 

Pablo Perez commented on NET-12:
--------------------------------

One thing, before calling retrieveFile() I have a getStatus() call.

The output is this one:
211-xxxxxxx.com FTP server status:
     Version 4.1 Thu Dec 7 16:20:00 CST 2006
     Connected to 9.18.126.91 (::ffff:9.18.126.91)
     Logged in as xxxxxx

     No data connection

211 End of Status



Is it normal to get a "No data connection" there?

> [net] FTPClient.retrieveFile() results in 0 byte files
> ------------------------------------------------------
>
>                 Key: NET-12
>                 URL: https://issues.apache.org/jira/browse/NET-12
>             Project: Commons Net
>          Issue Type: Bug
>    Affects Versions: 1.4
>         Environment: Operating System: HP-UX
> Platform: HP
>            Reporter: Steven LeVander
>
> 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;
>               }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to