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.info;
21
22 import org.waarp.common.command.ReplyCode;
23 import org.waarp.common.command.exception.CommandAbstractException;
24 import org.waarp.ftp.core.command.AbstractCommand;
25 import org.waarp.ftp.core.exception.FtpNoFileException;
26 import org.waarp.ftp.core.exception.FtpNoTransferException;
27 import org.waarp.ftp.core.file.FtpFile;
28 import org.waarp.ftp.core.utils.FtpChannelUtils;
29
30 import java.util.List;
31
32
33
34
35 public class STAT extends AbstractCommand {
36 @Override
37 public final void exec() throws CommandAbstractException {
38 final String path;
39 String message;
40 message = "STATUS information\nNo FtpFile currently in transfer\n";
41 FtpFile file = null;
42 try {
43 file = getSession().getDataConn().getFtpTransferControl()
44 .getExecutingFtpTransfer().getFtpFile();
45 } catch (final FtpNoFileException ignored) {
46
47 } catch (final FtpNoTransferException ignored) {
48
49 }
50 if (file != null) {
51 if (file.isInReading()) {
52 message = "STATUS information\nFile currently in Retrieve transfer\n";
53 } else if (file.isInWriting()) {
54 message = "STATUS information\nFile currently in Store transfer\n";
55 }
56 }
57 if (!hasArg()) {
58
59 message += getSession().getDataConn().getStatus();
60 message += "\nControl: " +
61 FtpChannelUtils.nbCommandChannels(getConfiguration()) +
62 " Data: " +
63 FtpChannelUtils.nbDataChannels(getConfiguration()) +
64 " Binded: " + getConfiguration().getFtpInternalConfiguration()
65 .getNbBindedPassive();
66 message += "\nEnd of Status";
67 getSession().setReplyCode(ReplyCode.REPLY_211_SYSTEM_STATUS_REPLY,
68 message);
69 } else {
70
71 path = getArg();
72 final List<String> filesInfo = getSession().getDir().listFull(path, true);
73 final StringBuilder builder =
74 new StringBuilder().append("List of files from ").append(path)
75 .append('\n');
76 for (final String newfileInfo : filesInfo) {
77 builder.append(newfileInfo).append('\n');
78 }
79 builder.append("End of Status");
80 message += builder.toString();
81 getSession().setReplyCode(ReplyCode.REPLY_212_DIRECTORY_STATUS, message);
82 }
83 }
84
85 }