1 /* 2 * Copyright 2007 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.mockftpserver.stub.command; 17 18 import org.mockftpserver.core.command.Command; 19 import org.mockftpserver.core.command.CommandHandler; 20 import org.mockftpserver.core.command.InvocationRecord; 21 import org.mockftpserver.core.command.ReplyCodes; 22 import org.mockftpserver.core.session.Session; 23 24 import java.io.IOException; 25 import java.net.InetAddress; 26 27 /** 28 * CommandHandler for the EPSV (Extended Address Passive Mode) command. Request the Session to switch 29 * to passive data connection mode. Return a reply code of 229, along with response text of the form: 30 * "<i>Entering Extended Passive Mode (|||PORT|)</i>", where <i>PORT</i> is the 16-bit TCP port 31 * address of the data connection on the server to which the client must connect. 32 * See RFC2428 for more information. 33 * <p/> 34 * Each invocation record stored by this CommandHandler contains no data elements. 35 * 36 * @author Chris Mair 37 * @version $Revision$ - $Date$ 38 */ 39 public class EpsvCommandHandler extends AbstractStubCommandHandler implements CommandHandler { 40 41 /** 42 * Constructor. Initialize the replyCode. 43 */ 44 public EpsvCommandHandler() { 45 setReplyCode(ReplyCodes.EPSV_OK); 46 } 47 48 /** 49 * @throws java.io.IOException 50 * @see org.mockftpserver.core.command.CommandHandler#handleCommand(org.mockftpserver.core.command.Command, org.mockftpserver.core.session.Session) 51 */ 52 public void handleCommand(Command command, Session session, InvocationRecord invocationRecord) 53 throws IOException { 54 55 int port = session.switchToPassiveMode(); 56 InetAddress server = session.getServerHost(); 57 LOG.debug("server=" + server + " port=" + port); 58 sendReply(session, Integer.toString(port)); 59 } 60 61 }