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