Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
8.9k views
in Java FTP by (280 points)
Heya,

I'm looking for some examples on how to use FTPS. I can connect and everything works fine using filezilla, but using the java library, the remote directory listing fails, but I don't really understand the error message.

error message is:

11:05:12,155  INFO WinituJob:138 - Creating FTP client
11:05:12,520  INFO WinituJob:141 - Setting remote host
11:05:12,521  INFO WinituJob:153 - Connecting to server..... 
11:05:13,968  INFO WinituJob:162 - Connected and logged in to server
11:05:13,970  INFO WinituJob:164 - Getting current directory listing
com.enterprisedt.net.puretls.SSLHandshakeFailedException: com.enterprisedt.net.puretls.SSLPrematureCloseException: Short read
        at com.enterprisedt.net.puretls.i.G(Unknown Source)
        at com.enterprisedt.net.puretls.SSLSocket.handshake(Unknown Source)
        at com.enterprisedt.net.ftp.ssl.C.C(Unknown Source)
        at com.enterprisedt.net.ftp.ssl.C.getInputStream(Unknown Source)
        at com.enterprisedt.net.ftp.pro.ProFTPClient.getInputStream(Unknown Source)
        at com.enterprisedt.net.ftp.FTPClient.A(Unknown Source)
        at com.enterprisedt.net.ftp.FTPClient.dir(Unknown Source)
        at com.enterprisedt.net.ftp.async.internal.DirectoryNameListTask.run(Unknown Source)
        at com.enterprisedt.net.ftp.async.internal.FTPTaskProcessor$_A.run(Unknown Source)


My code...

         log.info("Creating FTP client");
                        ftp = new SecureFileTransferClient();

         log.info("Setting remote host");

         ftp.setRemoteHost("app01.winitucom.com");
         ftp.setUserName("sip.intercity-nl.com");
         ftp.setPassword("XXXXXXXXX");
         ftp.setContentType(FTPTransferType.BINARY);
                        ftp.setServerValidationEnabled(false);
                        ftp.setProtocol(Protocol.FTPS_IMPLICIT);
                        ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
                        //ftp.setInitialRemoteDirectory("daily");
                        //ftp.setRemotePort(990);

         log.info("Connecting to server..... ");
         try {
            ftp.connect();
         } catch (Exception e) {
            log.error("Problem connecting");
                                e.printStackTrace();
            throw new ApplicationException("Problem connecting to " + ftp.getRemoteHost());
         }

         log.info("Connected and logged in to server");

         log.info("Getting current directory listing");

                        String[] files;
                        try {
                            files = ftp.directoryNameList();
                        } catch (Exception e){
                            e.printStackTrace();
                            throw new ApplicationException("Problem listing files on " + ftp.getRemoteHost());
                        }

8 Answers

0 votes
by (280 points)
Ah got it.

I needed a

ftp.auth(SSLFTPClient.PROT_PRIVATE);

after the

ftp.connect();

This fixed it.


Full code:
         log.info("Creating FTP client");
                        ftp = new SSLFTPClient();
                        ftp.setImplicitFTPS(true);
                        ftp.setRemoteHost("app01.winitucom.com");
                        ftp.setValidateServer(false);
                        ftp.setConfigFlags(SSLFTPClient.ConfigFlags.DISABLE_SSL_CLOSURE);
         log.info("Setting remote host");
         try {
            ftp.connect();
                                log.info("sending auth()");
                                ftp.auth(SSLFTPClient.PROT_PRIVATE);
                                log.info("Logging in..... ");
                                ftp.login("sip.intercity-nl.com","XXXXXXX");
                                log.info("Setting connect mode..... ");
                                ftp.setConnectMode(FTPConnectMode.PASV);

                                log.info("Setting transfer type..... ");
                                ftp.setType(FTPTransferType.BINARY);
                       }
0 votes
by (162k points)
Great, good to hear you fixed it!
0 votes
by (280 points)
Thanks Bruce.

Off topic perhaps, but how can I get enterprisedt logger messages? I've tried modifying my log4j by adding this line...

log4j.logger.com.enterprisedt=info, stdout

But this doesn't seem to work?
0 votes
by (162k points)
Here's how to set up logging, including log4j integration:

http://www.enterprisedt.com/products/ed ... gging.html
0 votes
by (280 points)
I assume you mean like this:

System.setProperty("edtftp.log.log4j", "true");

(and then having this in log4j)

log4j.logger.com.enterprisedt=info, stdout

but this doesn't work. I've tried the System.setProperty() in various places (Application start; during creation of the job object that does the FTP stuff; after the creation of the SSLFTPClient object).

Also: Where do I need to put the licence registration? Before the creation of the SSLFTPClient object I assume:

com.enterprisedt.util.license.License.setLicenseDetails("XXXX", "XXXXXXX");
0 votes
by (162k points)
Yes do the license reg before creating SSLFTPClient.

Use:

-Dedtftp.log.log4j=true

Here's the log4j.properties I've got here:

log4j.rootLogger=, A1
log4j.appender.A1=org.apache.log4j.FileAppender
log4j.appender.A1.File=log4j.log
log4j.appender.A1.Threshold=DEBUG
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n
0 votes
by (280 points)
I can't this to work whatever I try: -D<property> option in tomcat server didn't work either, even after removing all references to trying to set this within code, so my tomcat start options are '-XX:+AggressiveHeap -XX:MaxPermSize=128m -Xms512m -Xmx1024m -Dedtftp.log.log4j=true' - this should work, but doesn't). It may be a tomcat problem perhaps.

log4j.jar is definitely on the classpath - I log pretty much everything there - here's a bit of my log4j file:

log4j.logger.org.quartz=error, logfile
log4j.logger.net.sf.jasperreports=error, stdout
log4j.logger.org.springframework=info, stdout
log4j.logger.org.hibernate=error,stdout
log4j.logger.test=info, logfile
log4j.logger.net.sf.jasperreports=info, stdout
log4j.logger.com.enterprisedt=info, stdout

(which all works lovely apart from the enterprisedt bit).

It doesn't really matter - thank you for trying Bruce, but I'm just not bright enough to do this I think!!!

I can cope without logging as it seems to be working ok now anyway, and as I'm using lots of logging within my own module anyway so it's pretty clear when and where, say, ftp.connect() fails if it does.

Thanks for all your help

- Jon
0 votes
by (162k points)
I haven't tried in Tomcat, but try removing this line:

log4j.logger.com.enterprisedt

and add the lines above (which set up the root logger).

Categories

...