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