chrismair | 00dc7bd | 2014-05-11 21:21:28 +0000 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright 2008 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.fake.command;
|
| 17 |
|
| 18 | import org.mockftpserver.core.command.Command;
|
| 19 | import org.mockftpserver.core.command.ReplyCodes;
|
| 20 | import org.mockftpserver.core.session.Session;
|
| 21 | import org.mockftpserver.core.util.PortParser;
|
| 22 |
|
| 23 | import java.net.InetAddress;
|
| 24 |
|
| 25 | /**
|
| 26 | * CommandHandler for the PASV command. Handler logic:
|
| 27 | * <ol>
|
| 28 | * <li>If the user has not logged in, then reply with 530</li>
|
| 29 | * <li>Otherwise, request the Session to switch to passive data connection mode. Return a reply code of 227,
|
| 30 | * along with response text of the form: "<i>(h1,h2,h3,h4,p1,p2)</i>", where <i>h1..h4</i> are the
|
| 31 | * 4 bytes of the 32-bit internet host address of the server, and <i>p1..p2</i> are the 2
|
| 32 | * bytes of the 16-bit TCP port address of the data connection on the server to which
|
| 33 | * the client must connect. See RFC959 for more information.</i>
|
| 34 | * </ol>
|
| 35 | *
|
| 36 | * @author Chris Mair
|
| 37 | * @version $Revision$ - $Date$
|
| 38 | */
|
| 39 | public class PasvCommandHandler extends AbstractFakeCommandHandler {
|
| 40 |
|
| 41 | protected void handle(Command command, Session session) {
|
| 42 | verifyLoggedIn(session);
|
| 43 |
|
| 44 | int port = session.switchToPassiveMode();
|
| 45 | InetAddress server = session.getServerHost();
|
| 46 | LOG.debug("server=" + server + " port=" + port);
|
| 47 | String hostAndPort = PortParser.convertHostAndPortToCommaDelimitedBytes(server, port);
|
| 48 |
|
| 49 | sendReply(session, ReplyCodes.PASV_OK, "pasv", list(hostAndPort));
|
| 50 | }
|
| 51 |
|
| 52 | }
|