[英]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.