1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.ftp.core.command.rfc2428;
21
22 import org.waarp.common.command.ReplyCode;
23 import org.waarp.common.command.exception.Reply522Exception;
24 import org.waarp.common.logging.WaarpLogger;
25 import org.waarp.common.logging.WaarpLoggerFactory;
26 import org.waarp.ftp.core.command.AbstractCommand;
27 import org.waarp.ftp.core.utils.FtpChannelUtils;
28
29 import java.net.InetSocketAddress;
30
31
32
33
34 public class EPRT extends AbstractCommand {
35 private static final WaarpLogger logger =
36 WaarpLoggerFactory.getInstance(EPRT.class);
37
38 @Override
39 public final void exec() throws Reply522Exception {
40
41 if (!hasArg()) {
42 final InetSocketAddress inetSocketAddress =
43 getSession().getDataConn().getRemoteAddress();
44 logger.debug("Active connect to {}", inetSocketAddress);
45 getSession().getDataConn().setActive(inetSocketAddress);
46 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
47 "EPRT command successful on (" +
48 FtpChannelUtils.get2428Address(
49 inetSocketAddress) + ')');
50 return;
51 }
52
53
54 final InetSocketAddress inetSocketAddress =
55 FtpChannelUtils.get2428InetSocketAddress(getArg());
56 if (inetSocketAddress == null) {
57
58 throw new Reply522Exception("Can't get SocketAddress from " + getArg());
59 }
60
61
62 logger.debug("Active connect to {}", inetSocketAddress);
63 getSession().getDataConn().setActive(inetSocketAddress);
64 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
65 "EPRT command successful on (" +
66 FtpChannelUtils.get2428Address(
67 inetSocketAddress) + ')');
68 }
69 }