1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.ftp.core.command.internal;
22
23 import goldengate.common.command.ReplyCode;
24 import goldengate.common.command.exception.Reply500Exception;
25 import goldengate.common.command.exception.Reply501Exception;
26 import goldengate.ftp.core.command.AbstractCommand;
27
28
29
30
31
32
33
34 public class LIMITBANDWIDTH extends AbstractCommand {
35
36
37
38
39
40 public void exec() throws Reply501Exception, Reply500Exception {
41 if (!getSession().getAuth().isAdmin()) {
42
43 throw new Reply500Exception("Command Not Allowed");
44 }
45 if (!hasArg()) {
46
47 getConfiguration().changeNetworkLimit(0, 0);
48 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
49 "Limit reset to default");
50 return;
51 }
52 String[] limits = getArgs();
53 long writeLimit = 0;
54 long readLimit = 0;
55 try {
56 if (limits.length == 1) {
57 writeLimit = Long.parseLong(limits[0]);
58 readLimit = writeLimit;
59 } else {
60 writeLimit = Long.parseLong(limits[0]);
61 readLimit = Long.parseLong(limits[1]);
62 }
63 } catch (NumberFormatException e) {
64 throw new Reply501Exception(getCommand() +
65 " ([write and read limits in b/s] | [write limit in b/s] [read limit in b/s]");
66 }
67 getConfiguration().changeNetworkLimit(writeLimit, readLimit);
68 getSession().setReplyCode(ReplyCode.REPLY_200_COMMAND_OKAY,
69 "Limit set to new values");
70 }
71
72 }