title: Unable to connect to remote FileZilla ftp server from java application
body: <p>I have a remote FileZilla ftp server running on a windows machine. The ftp server requires <strong>Explicit FTP over TLS</strong>. The protocol is FTP and NOT SFTP. I cannot change the settings for this server. I can connect to this server using the filezilla gui client just fine.</p>
  
  <p>Now I need to connect to the FileZilla server through a java application using org.apache.commons.net:</p>
  
  <pre><code>  private void connect(String host, String user, String password) {
      try {
        FTPSClient ftpClient = new FTPSClient(false);
        ftpClient.connect(host);
        int reply = ftpClient.getReplyCode();
        if (FTPReply.isPositiveCompletion(reply)) {
          // Login
          if (ftpClient.login(user, password)) {
  
            // Set protection buffer size
            ftpClient.execPBSZ(0);
            // Set data channel protection to private
            ftpClient.execPROT("P");
            // Enter local passive mode
            ftpClient.enterLocalPassiveMode();
            ftpClient.logout();
          } else {
            System.out.println("FTP login failed");
          }
          // Disconnect
          ftpClient.disconnect();
        } else {
          System.out.println("FTP connect to host failed");
        }
      } catch (IOException ioe) {
        ioe.printStackTrace();
        System.out.println("FTP client received network error");
      }
    }
  </code></pre>
  
  <p>but when I run the above code I get:</p>
  
  <pre><code>javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateExpiredException: NotAfter: Thu Aug 30 13:31:23 CEST 2012
      at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1764)
  </code></pre>
  
  <p>when it comes to:</p>
  
  <pre><code>  ftpClient.connect(host);
  </code></pre>
  
  <p>Any ideas on how to connect to a Filezilla server from java code using eg. org.apache.commons.net ?</p>
  
  <p>EDIT:
  I have now tried to change to FTPClient (even though that does allow me to setup <strong>Explicit TLS</strong>):</p>
  
  <pre><code>  FTPClient ftpClient = new FTPClient();
    // Connect to host
    ftpClient.connect(host);
    int reply = ftpClient.getReplyCode();
    if (FTPReply.isPositiveCompletion(reply)) {
  
      // Login
      boolean login = ftpClient.login(user, password);
      if (login) {
        ftpClient.enterLocalPassiveMode();
        ftpClient.logout();
      } else {
        System.out.println("FTP login failed");
      }
  </code></pre>
  
  <p>but then login=false and I get: "FTP login failed". And if I debug the apache source I see the reply code is: 530 = "Not logged in" : <a href="http://en.wikipedia.org/wiki/List_of_FTP_server_return_codes" rel="nofollow">http://en.wikipedia.org/wiki/List_of_FTP_server_return_codes</a></p>