3

I need to mock "FTPS" server as part of unit testing. I am getting "javax.net.ssl.SSLException: 502 Command not implemented: AUTH" via using mock FTPS Server.

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.

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. 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)
Abhishek Kumar
  • 435
  • 1
  • 6
  • 16

1 Answers1

1

Got confirmation from Chris that, MockFTPServer does not support FTPS.

Reference Link - https://sourceforge.net/p/mockftpserver/discussion/748297/thread/d69457a91a/

Abhishek Kumar
  • 435
  • 1
  • 6
  • 16