FtpServerFtpLet implements Ftplet { @Override public FtpletResult beforeCommand(FtpSession session, FtpRequest request) { String command = request.getCommand().toUpperCase(); if (log.isDebugEnabled()) { log.debug(String.format("Received FTP command: '%s'", command)); } if (endpointConfiguration.isAutoLogin() && (command.equals(FTPCmd.USER.getCommand()) || command.equals(FTPCmd.PASS.getCommand()))) { return FtpletResult.DEFAULT; } if (Stream.of(StringUtils.commaDelimitedListToStringArray(endpointConfiguration.getAutoHandleCommands())).anyMatch(cmd -> cmd.trim().equals(command))) { return FtpletResult.DEFAULT; } FtpMessage response = handleMessage(FtpMessage.command(FTPCmd.valueOf(command)).arguments(request.getArgument())); if (response.hasReplyCode()) { writeFtpReply(session, response); return FtpletResult.SKIP; } return FtpletResult.DEFAULT; } FtpServerFtpLet(FtpEndpointConfiguration endpointConfiguration, EndpointAdapter endpointAdapter); FtpMessage handleMessage(FtpMessage request); @Override void init(FtpletContext ftpletContext); @Override void destroy(); @Override FtpletResult beforeCommand(FtpSession session, FtpRequest request); @Override FtpletResult afterCommand(FtpSession session, FtpRequest request, FtpReply reply); @Override FtpletResult onConnect(FtpSession session); @Override FtpletResult onDisconnect(FtpSession session);  }
@Test public void testAutoLogin() { reset(endpointAdapter, ftpSession, ftpRequest); when(ftpRequest.getCommand()).thenReturn(FTPCmd.USER.getCommand()).thenReturn(FTPCmd.PASS.getCommand()); when(ftpRequest.getArgument()).thenReturn("foo").thenReturn("secret"); FtpletResult result = ftpLet.beforeCommand(ftpSession, ftpRequest); Assert.assertEquals(result, FtpletResult.DEFAULT); result = ftpLet.beforeCommand(ftpSession, ftpRequest); Assert.assertEquals(result, FtpletResult.DEFAULT); }