You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Robert Kast <rk...@voiceobjects.com> on 2007/08/06 15:17:35 UTC

Commons Net FTPClient: initiateListParsing delivers empty result after migration from Windows to Linux

Hi all,

I use the FTPClient of Commons Net to retrieve files from
an FTP server and delete them after retrieval. This works
very well on my Windows 2000 Professional notebook using
a JDK 1.5.0.

However, if I move the java files to my target system
(Linux server) and recompile the code on JDK 1.4.2_11,
no files are fetched from the FTP server despite of
masses of files being available for retrieval (which
the Windows-based JVM process would fetch). 

"engine.hasNext()" delivers false so the code for file
retrieval is not executed.

Using a different parser (UnixFTPEntyParser) did not
yield a solution on Linux.

I would be more than glad if any of you could give me a hint
on how to solve this miracle.

Thanks in advance,

Robert


===========================================
===========================================
Code snippet is:
===========================================
===========================================


    FTPClient ftp = new FTPClient();
    
    ftp.connect( ftpServer );
    verifyFtpReply ( "connect to server", ftp.getReplyCode(),
ftp.getReplyString());
    ftp.login( ftpUser, ftpPassword );
    verifyFtpReply ( "user/pwd login to server", ftp.getReplyCode(),
ftp.getReplyString());
    
    timestampBefore = (new java.util.Date()).getTime();
    FTPListParseEngine engine = ftp.initiateListParsing();
    // fails as well: FTPListParseEngine engine =
ftp.initiateListParsing("org.apache.commons.net.ftp.parser.UnixFTPEntryP
arser", ftpRemoteDir);
    verifyFtpReply ( "initiateListParsing", ftp.getReplyCode(),
ftp.getReplyString());
    timestampAfter = (new java.util.Date()).getTime();
    
    while (engine.hasNext()) {
        FTPFile[] files = engine.getNext(25);  // "page size" you want
        
        _log.debug("Found set of "+files.length+" files in remote dir
"+ftpRemoteDir + " (" + substrLess2(ftp.getReplyString())+")",
timestampBefore, timestampAfter);
    
    	for( int i=0; i<files.length; i++ ) {
    		if ( files[i] != null && files[i].isFile() ) {

                [...file retrieval...]

    		}
        }
    }

[snip]

    
    private static String substrLess2 (String sourceStr) { 
        return sourceStr.substring(0,sourceStr.length()-2);
    }
    
    private static void verifyFtpReply (String comment, int replyCode,
String replyString) throws Exception {
        if ( !FTPReply.isPositiveCompletion(replyCode) ) {
            throw new Exception ("FTP Error on "+comment+"
("+replyCode+"/"+substrLess2(replyString)+")");
        }
    }

===========================================
===========================================
Linux version information
===========================================
===========================================

#uname -a
Linux testhost 2.6.9-34.ELsmp #1 SMP Fri Feb 24 16:54:53 EST 2006 i686
i686 i386 GNU/Linux
#java -version
java version "1.4.2_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)
#

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org