HTTPS Client with FTP Login Error: javax.net.ssl.SSLException: 502 SSLv23/TLSv1 java

霸气de小男生 提交于 2021-02-07 11:01:49

问题


I am pretty new to Java so the more you explain the more I learn, and less questions I will ask ;) I am trying to program a client to connect to ftp.availity.com but I cannot for the life of me get the client to login. I have tried changing the port numbers (443, 20, etc) but they all do not return a response in the console log and it only returns a timeout error. The only one I can get some action with is port 21. I know this is FTP and I think that may be where there error is coming from but I have no idea how to correct it because obviously changing the port # doesn't correct the issue. Any help would be appreciated!

Here's my code:

import java.io.IOException;
import org.apache.commons.net.ftp.*;

public class FTPApp {
private static void showServerReply(FTPSClient ftpClient) {
    String[] replies = ftpClient.getReplyStrings();
    if (replies != null && replies.length > 0) {
        for (String aReply : replies) {
            System.out.println("SERVER: " + aReply);
        }
    }
}

public static void main(String[] args) {

    String server = "ftp.availity.com";
    int port = 21;
    String user = "user";
    String pass = "pass";
    FTPSClient ftpClient = new FTPSClient();

    try {
        ftpClient.connect( server, port);   
        showServerReply(ftpClient);
        int replyCode = ftpClient.getReplyCode();
        if (!FTPReply.isPositiveCompletion(replyCode)) {
            System.out.println("Operation failed. Server reply code: " + replyCode);
            return;
        }
        boolean success = ftpClient.login(user, pass);
        showServerReply(ftpClient);
        if (!success) {
            System.out.println("Could not login to the server");
            return;
        } else {
            System.out.println("LOGGED IN SERVER");
        }
    } catch (IOException ex) {
        System.out.println("Oops! Something wrong happened");
        ex.printStackTrace();
    }
}

}

Here's the error:

Oops! Something wrong happened
javax.net.ssl.SSLException: 502 SSLv23/TLSv1
at org.apache.commons.net.ftp.FTPSClient.execAUTH(FTPSClient.java:242)
at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:225)
at org.apache.commons.net.SocketClient._connect(SocketClient.java:244)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
at FTPApp.main(FTPApp.java:23)

回答1:


I have tried changing the port numbers (443, 20, etc) but they all do not return a response in the console log and it only returns a timeout error. The only one I can get some action with is port 21.

Which is no suprpise: Port 443 is HTTPS which has nothing to do with FTP at all. Port 20 is the data port use as a source of data connection with FTP, but is not a port which expects connections. Port 21 is the FTP control port, i.e. this is the one where connections actually expected.

Oops! Something wrong happened javax.net.ssl.SSLException: 502 SSLv23/TLSv1 at org.apache.commons.net.ftp.FTPSClient.execAUTH(FTPSClient.java:242)

The command used here is AUTH TLS which is used by a client to upgrade a plain FTP connection (as required on port 21) to FTPS, i.e. FTP over TLS. It is similar to STARTTLS to upgrade plain SMTP connections to SMTP over TLS.

AUTH TLS expects a successful response code from the server. Instead it gets code 502 which stands for "Command not implemented". This simply means that the FTP server you talk to does not support FTP over TLS and there is nothing you can do from the client side to force this.

If you have control over the server you need to configure the server for TLS support. If you don't have control over the server you can either use plain unprotected FTP (i.e. not FTPSClient but FTPClient) or give up.

I am pretty new to Java ...

None of this requires any knowledge of Java. It only requires knowledge of how FTP and FTPS work.




回答2:


Adding my comment here as i do not have enough reputation(joined stackoverflow recently:). From the error it seems to be an issue with the SSL/TLS negotiation which has lead to 502 return code. You can add -Djavax.net.debug=all as jvm property to debug more about the exact SSL negotiation issue.




回答3:


I FIGURED IT OUT!

the ftp.availity.com was the url I would go to to login but when putting it in for the host, to make it secure, all I had to do was keep the "FTPSClient" but make the host "ftps.availity.com" not just "ftp.availity.com".

The ftp server is setup under Axway SecureTransport or Tumbleweed so hopefully anyone with the same issue can find this thread!!!

Thank you all so much for helping me!



来源:https://stackoverflow.com/questions/50868600/https-client-with-ftp-login-error-javax-net-ssl-sslexception-502-sslv23-tlsv1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!