Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-702

FTPSClient fails on listFiles()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 3.7.2, 3.8.0
    • None
    • FTP
    • None

    Description

      Calling ftpsclient.listFiles() fails in all ways.

      See the program below.

      Not having the "magic incantations" (execPROT("P")) makes it fail because it returns no files without ANY indication of error, even though the remote server answered with a "522 data connections must be encrypted" error. This is silent failure.

      If you do add the execPROC call then listFiles fails with the following exception:

      Exception in thread "main" javax.net.ssl.SSLProtocolException: Received close_notify during handshakeException in thread "main" javax.net.ssl.SSLProtocolException: Received close_notify during handshake at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:129) at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255) at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:250) at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:181) at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164) at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1155) at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1125) at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:823) at java.base/sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at java.base/sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at java.base/sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) at java.base/java.io.InputStreamReader.read(InputStreamReader.java:185) at java.base/java.io.BufferedReader.fill(BufferedReader.java:161) at java.base/java.io.BufferedReader.readLine(BufferedReader.java:326) at java.base/java.io.BufferedReader.readLine(BufferedReader.java:392) at org.apache.commons.net.ftp.FTPFileEntryParserImpl.readNextEntry(FTPFileEntryParserImpl.java:53) at org.apache.commons.net.ftp.FTPListParseEngine.read(FTPListParseEngine.java:139) at org.apache.commons.net.ftp.FTPListParseEngine.readServerList(FTPListParseEngine.java:119) at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2264) at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2390) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2651) at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2595) at nl.skarp.dataloader.datasources.TestFtps.main(TestFtps.java:40)

       

      The program I used:

      public class TestFtps {
         static public void main(String[] args) throws Exception {
            FTPSClient client = new FTPSClient();
            client.connect("localhost");
      
            int reply = client.getReplyCode();
            if(!FTPReply.isPositiveCompletion(reply)) {
               throw new DataAccessConfigException("ftp(s) server refused connection");
            }
            client.enterLocalPassiveMode();                   // For firewall usage
      
            System.out.println("ftp: login");
            if(!client.login("jal", "possward")) {
               throw new DataAccessConfigException("ftp(s) login failed");
            }
      
            client.setFileType(FTP.BINARY_FILE_TYPE);
            client.type(FTP.BINARY_FILE_TYPE);
      
            System.out.println("ftp: set passive mode");
      
            //client.enterLocalPassiveMode();                 // For firewall usage
            System.out.println("Fixing ftps listing");
      
            FTPSClient ftpsClient = (FTPSClient) client;
            ftpsClient.execPROT("P");
            ftpsClient.execPBSZ(0);
      
            FTPFile[] ftpFiles = client.listFiles();
            for(FTPFile ftpFile : ftpFiles) {
               System.out.println("Got file " + ftpFile.getName());
            }
         }
      }
      
      

       

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            fjalvingh Frits Jalvingh
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: