【问题标题】:How to create “FTPS” Mock Server for unit test in Java, Getting Error - javax.net.ssl.SSLException: 502 Command not implemented: AUTH如何在 Java 中为单元测试创​​建“FTPS”模拟服务器,出现错误 - javax.net.ssl.SSLException: 502 Command not implemented: AUTH
【发布时间】:2019-12-13 00:10:28
【问题描述】:

我需要模拟“FTPS”服务器作为单元测试的一部分。我通过使用模拟 FTPS 服务器得到“javax.net.ssl.SSLException: 502 Command not implemented: AUTH”。

我浏览了http://mockftpserver.sourceforge.net/How to create a "FTPS" Mock Server to unit test File Transfer in 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 ***");
    }
}

我使用上面的代码来连接 FTPS 服务器,但我遇到了以下错误。您能否提供任何输入来解决以下错误。

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)

【问题讨论】:

    标签: java mocking ftps apache-commons-net


    【解决方案1】:

    得到 Chris 的确认,MockFTPServer 不支持 FTPS。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多