1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.ftp.simpleimpl.control;
21
22 import io.netty.channel.Channel;
23 import org.waarp.common.command.exception.CommandAbstractException;
24 import org.waarp.common.command.exception.Reply502Exception;
25 import org.waarp.common.logging.WaarpLogger;
26 import org.waarp.common.logging.WaarpLoggerFactory;
27 import org.waarp.ftp.core.command.AbstractCommand;
28 import org.waarp.ftp.core.command.FtpCommandCode;
29 import org.waarp.ftp.core.command.service.MKD;
30 import org.waarp.ftp.core.control.BusinessHandler;
31 import org.waarp.ftp.core.data.FtpTransfer;
32 import org.waarp.ftp.core.session.FtpSession;
33 import org.waarp.ftp.filesystembased.FilesystemBasedFtpRestart;
34 import org.waarp.ftp.simpleimpl.file.FileBasedAuth;
35 import org.waarp.ftp.simpleimpl.file.FileBasedDir;
36
37
38
39
40
41
42 public class SimpleBusinessHandler extends BusinessHandler {
43 private static final String GBBH_TRANSFER = "GBBH: Transfer: {} ";
44
45
46
47 private static final WaarpLogger logger =
48 WaarpLoggerFactory.getLogger(SimpleBusinessHandler.class);
49
50 @Override
51 public void afterRunCommandKo(final CommandAbstractException e) {
52
53 if (getFtpSession().getCurrentCommand() instanceof MKD) {
54
55 } else {
56 logger.debug("GBBH: AFTKO: {} {}", getFtpSession(), e.getMessage());
57 }
58 }
59
60 @Override
61 public void afterRunCommandOk() throws CommandAbstractException {
62
63
64 }
65
66 @Override
67 public void beforeRunCommand() throws CommandAbstractException {
68
69
70 }
71
72 @Override
73 protected void cleanSession() {
74
75
76 }
77
78 @Override
79 public void exceptionLocalCaught(final Throwable e) {
80
81 logger.warn("GBBH: EXCEP: {} {}", getFtpSession(), e.getMessage());
82 }
83
84 @Override
85 public void executeChannelClosed() {
86
87
88
89 }
90
91 @Override
92 public void executeChannelConnected(final Channel channel) {
93
94
95 }
96
97 @Override
98 public final FileBasedAuth getBusinessNewAuth() {
99 return new FileBasedAuth(getFtpSession());
100 }
101
102 @Override
103 public final FileBasedDir getBusinessNewDir() {
104 return new FileBasedDir(getFtpSession());
105 }
106
107 @Override
108 public final FilesystemBasedFtpRestart getBusinessNewRestart() {
109 return new FilesystemBasedFtpRestart(getFtpSession());
110 }
111
112 @Override
113 public final String getHelpMessage(final String arg) {
114 return "This FTP server is only intend as a Gateway.\n" +
115 "This FTP server refers to RFC 959, 775, 2389, 2428, 3659, 4217 " +
116 "and supports XDIGEST, XCRC, XMD5 and XSHA1 commands.\n" +
117 "XCRC, XMD5 and XSHA1 take a simple filename as argument, XDIGEST " +
118 "taking algorithm (among CRC32, ADLER32, MD5, MD2, " +
119 "SHA-1, SHA-256, SHA-384, SHA-512) followed by filename " +
120 "as arguments," +
121 " and return \"250 digest-value is the digest of filename\".";
122 }
123
124 @Override
125 public final String getFeatMessage() {
126 final StringBuilder builder =
127 new StringBuilder("Extensions supported:").append('\n').append(
128 getDefaultFeatMessage());
129 if (getFtpSession().getConfiguration().getFtpInternalConfiguration()
130 .isAcceptAuthProt()) {
131 builder.append('\n').append(getSslFeatMessage());
132 }
133 builder.append("\nEnd");
134 return builder.toString();
135 }
136
137 @Override
138 public final String getOptsMessage(final String[] args)
139 throws CommandAbstractException {
140 if (args.length > 0) {
141 if (args[0].equalsIgnoreCase(FtpCommandCode.MLST.name()) ||
142 args[0].equalsIgnoreCase(FtpCommandCode.MLSD.name())) {
143 return getMLSxOptsMessage(args);
144 }
145 throw new Reply502Exception("OPTS not implemented for " + args[0]);
146 }
147 throw new Reply502Exception("OPTS not implemented");
148 }
149
150 @Override
151 public AbstractCommand getSpecializedSiteCommand(final FtpSession session,
152 final String line) {
153 return null;
154 }
155
156 @Override
157 public final void afterTransferDoneBeforeAnswer(final FtpTransfer transfer)
158 throws CommandAbstractException {
159 if (transfer.getCommand() == FtpCommandCode.APPE) {
160 logger.info(GBBH_TRANSFER + "{} {}", transfer.getCommand(),
161 transfer.getStatus(), transfer.getPath());
162 } else if (transfer.getCommand() == FtpCommandCode.RETR) {
163 logger.info(GBBH_TRANSFER + "{} {}", transfer.getCommand(),
164 transfer.getStatus(), transfer.getPath());
165 } else if (transfer.getCommand() == FtpCommandCode.STOR) {
166 logger.info(GBBH_TRANSFER + "{} {}", transfer.getCommand(),
167 transfer.getStatus(), transfer.getPath());
168 } else if (transfer.getCommand() == FtpCommandCode.STOU) {
169 logger.info(GBBH_TRANSFER + "{} {}", transfer.getCommand(),
170 transfer.getStatus(), transfer.getPath());
171 } else {
172 logger.warn("GBBH: Transfer unknown: {} {} {}", transfer.getCommand(),
173 transfer.getStatus(), transfer.getPath());
174
175 }
176 }
177 }