简体   繁体   English

如何为Java中的单元测试创​​建“ FTPS”模拟服务器,出现错误-javax.net.ssl.SSLException:502未实现的命令:AUTH

[英]How to create “FTPS” Mock Server for unit test in Java, Getting Error - javax.net.ssl.SSLException: 502 Command not implemented: AUTH

I need to mock "FTPS" server as part of unit testing. 我需要模拟“ FTPS”服务器作为单元测试的一部分。 I am getting "javax.net.ssl.SSLException: 502 Command not implemented: AUTH" via using mock FTPS Server. 我通过使用模拟FTPS服务器收到“ javax.net.ssl.SSLException:502命令未实现:AUTH”。

I went through http://mockftpserver.sourceforge.net/ and How to create a "FTPS" Mock Server to unit test File Transfer in Java but didn't find a way to connect as FTPS server. 我通过http://mockftpserver.sourceforge.net/如何创建“ FTPS”模拟服务器来对Java中的文件传输进行单元测试,却没有找到作为FTPS服务器进行连接的方法。

import java.io.File;

import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPSClient;
import org.mockftpserver.fake.FakeFtpServer;
import org.mockftpserver.fake.UserAccount;

public class FtpsMockTest {
    private FakeFtpServer fakeFtpServer;

    public FtpsMockTest(int port, String userName, String password, File homeDir){
        fakeFtpServer = new FakeFtpServer();
        fakeFtpServer.setServerControlPort(port);
        fakeFtpServer.addUserAccount(new UserAccount(userName, password, homeDir.getAbsolutePath()));
    }

    public static FTPSClient createFtpsClient(String hostname, Integer port, String username, String password)
            throws Exception {

        FTPSClient ftpsClient = new FTPSClient("TLS", false);

        ftpsClient.connect(hostname, port);
        ftpsClient.enterLocalPassiveMode();

        boolean loginStatus = ftpsClient.login(username, password);
        if (!loginStatus) {
            throw new Exception("FTPS client login failed.");
        }

        ftpsClient.execPBSZ(0);
        ftpsClient.execPROT("P");
        ftpsClient.setFileType(FTP.BINARY_FILE_TYPE);
        ftpsClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);

        return ftpsClient;
    }

    public static void main(String[] args) throws Exception {
        FtpsMockTest test = null;
        try {
            test = new FtpsMockTest(990, "test", "test", new File("C:\\FuncTest"));
            test.start();

            FTPSClient ftpsClient = createFtpsClient("127.0.0.1", 990, "test", "test");
            FTPFile[] listFiles = ftpsClient.listFiles("C:/Test");
            System.out.println("*** total available files ***" + listFiles.length);
        }finally {
            test.stop();
        }
    }

    public void start(){
        fakeFtpServer.start();
        System.out.println("**** FAKE FTPS Server Started ***");
    }

    public void stop(){
        fakeFtpServer.stop();
        System.out.println("**** FAKE FTPS Server Stopped ***");
    }
}

I used above code to connect FTPS server, but i am getting below error. 我使用上面的代码连接FTPS服务器,但出现以下错误。 Could you please provide any input to solve below error. 您能否提供任何输入以解决以下错误。

Exception in thread "main" javax.net.ssl.SSLException: 502 Command not implemented: AUTH.

    at org.apache.commons.net.ftp.FTPSClient.execAUTH(FTPSClient.java:214)
    at org.apache.commons.net.ftp.FTPSClient._connectAction_(FTPSClient.java:196)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:164)
    at org.apache.commons.net.SocketClient.connect(SocketClient.java:184)
    at com.asos.mule.core.connector.ftps.functional.FtpsMockTest.createFtpsClient(FtpsMockTest.java:25)
    at com.asos.mule.core.connector.ftps.functional.FtpsMockTest.main(FtpsMockTest.java:47)

Got confirmation from Chris that, MockFTPServer does not support FTPS. 克里斯(Chris)确认,MockFTPServer不支持FTPS。

Reference Link - https://sourceforge.net/p/mockftpserver/discussion/748297/thread/d69457a91a/ 参考链接-https: //sourceforge.net/p/mockftpserver/discussion/748297/thread/d69457a91a/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CordApp Java堆空间错误和javax.net.ssl.SSLException - CordApp Java Heap Space error and javax.net.ssl.SSLException 如何修复 javax.net.ssl.SSLException - How to fix javax.net.ssl.SSLException 带有FTP登录错误的HTTPS客户端:javax.net.ssl.SSLException:502 SSLv23 / TLSv1 java - HTTPS Client with FTP Login Error: javax.net.ssl.SSLException: 502 SSLv23/TLSv1 java “android javax.net.ssl.SSLException: 502 AUTH TLS OK”在华为智能手机上,但在三星智能手机上运行良好。 为什么? - "android javax.net.ssl.SSLException: 502 AUTH TLS OK" on HUAWEI smartphone but it works well on a SAMSUNG smartphone. Why? 获取方法抛出“javax.net.ssl.SSLException”异常 - Getting Method threw 'javax.net.ssl.SSLException' exception 如何创建“ FTPS”模拟服务器以对Java中的文件传输进行单元测试 - How to create a “FTPS” Mock Server to unit test File Transfer in Java Android中的“javax.net.ssl.SSLException:不受信任的服务器证书”异常 - “javax.net.ssl.SSLException: Not trusted server certificate” exception in Android urlconnection javax.net.ssl.SSLException:java.lang.IllegalStateException - urlconnection javax.net.ssl.SSLException: java.lang.IllegalStateException 执行ftp时出现错误“ javax.net.ssl.SSLException:530,请使用USER和PASS登录” - Getting error “javax.net.ssl.SSLException: 530 Please login with USER and PASS” while performing ftp javax.net.ssl.SSLException:连接重置 - javax.net.ssl.SSLException: Connection reset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM