首页 > 解决方案 > FTPS协议版本

问题描述

我正在尝试连接到 ftps 服务器,但我一直都有 SSL 异常“收到致命警报:protocol_version”。我修改了我的代码 1000 次以寻找正确的实现,但每次都出现相同的错误(我的 jar 在 java7 中运行)

我尝试了什么:

我的代码:

public FTPConnection(String host, String username, String password, boolean passive) throws IOException {
            this.host = host;
            System.setProperty("jdk.tls.useExtendedMasterSecret", "false");
            System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
            this.clientFtps = new FTPSClient("TLS", false);
            try{
            this.clientFtps.connect(host, 21);
            }catch (SSLException e){
                log.debug(" port : " + this.clientFtps.getDefaultPort() + " Reply : " + this.clientFtps.getReplyString());
                log.debug("catched exception : " + e);
            }
            if (username != null)
                try{
                    if (pasv) {
                        this.clientFtps.enterLocalPassiveMode();
                    } else {
                        this.clientFtps.enterLocalActiveMode();
                    }
                    this.clientFtps.login(username, password);
                    log.debug(this.clientFtps.getReplyString());
                }
            catch (IOException ex){
                ex.printStackTrace();
            }
                this.clientFtps.setFileType(FTP.BINARY_FILE_TYPE);
                this.clientFtps.setFileTransferMode(FTP.BINARY_FILE_TYPE);
                log.debug("the type of ftp file is : " + FTP.BINARY_FILE_TYPE);
        }

我的错误:

捕获的异常:javax.net.ssl.SSLException:收到致命警报:protocol_version

服务器返回什么:

https.protocols : TLSv1,TLSv1.1,TLSv1.2 端口: 21 回复: 234 AUTH TLS 成功

标签: javaftps

解决方案


推荐阅读