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.internal;
21
22 import org.waarp.common.command.ReplyCode;
23 import org.waarp.common.command.exception.Reply500Exception;
24 import org.waarp.common.command.exception.Reply501Exception;
25 import org.waarp.ftp.core.command.AbstractCommand;
26
27
28
29
30 public class LIMITBANDWIDTH extends AbstractCommand {
31 @Override
32 public final void exec() throws Reply501Exception, Reply500Exception {
33 if (!getSession().getAuth().isAdmin()) {
34
35 throw new Reply500Exception("Command Not Allowed");
36 }
37 if (!hasArg()) {
38
39 getConfiguration().changeNetworkLimit(0, 0);
40 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
41 "Limit reset to default");
42 return;
43 }
44 final String[] limits = getArgs();
45 final long writeLimit;
46 final long readLimit;
47 try {
48 if (limits.length == 1) {
49 writeLimit = Long.parseLong(limits[0]);
50 readLimit = writeLimit;
51 } else {
52 writeLimit = Long.parseLong(limits[0]);
53 readLimit = Long.parseLong(limits[1]);
54 }
55 } catch (final NumberFormatException e) {
56 throw new Reply501Exception(getCommand() +
57 " ([write and read limits in b/s] | [write limit in b/s] [read limit in b/s]");
58 }
59 getConfiguration().changeNetworkLimit(writeLimit, readLimit);
60 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
61 "Limit set to new values");
62 }
63
64 }