1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.waarp.ftp.core.command.info;
19
20 import java.util.List;
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
31
32
33
34
35
36 public class STAT extends AbstractCommand {
37 @Override
38 public void exec() throws CommandAbstractException {
39 String path = null;
40 String message = null;
41 message = "STATUS information\nNo FtpFile currently in transfer\n";
42 FtpFile file = null;
43 try {
44 file = getSession().getDataConn().getFtpTransferControl()
45 .getExecutingFtpTransfer().getFtpFile();
46 } catch (FtpNoFileException e) {
47 } catch (FtpNoTransferException e) {
48 }
49 if (file != null) {
50 if (file.isInReading()) {
51 message = "STATUS information\nFile currently in Retrieve transfer\n";
52 } else if (file.isInWriting()) {
53 message = "STATUS information\nFile currently in Store transfer\n";
54 }
55 }
56 if (!hasArg()) {
57
58 message += getSession().getDataConn().getStatus();
59 message += "\nControl: " +
60 FtpChannelUtils.nbCommandChannels(getConfiguration()) +
61 " Data: " +
62 FtpChannelUtils.nbDataChannels(getConfiguration()) +
63 " Binded: " +
64 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 List<String> filesInfo = getSession().getDir().listFull(path, true);
73 StringBuilder builder = new StringBuilder().append("List of files from ").append(path).append('\n');
74 for (String newfileInfo : filesInfo) {
75 builder.append(newfileInfo).append('\n');
76 }
77 builder.append("End of Status");
78 message += builder.toString();
79 getSession().setReplyCode(ReplyCode.REPLY_212_DIRECTORY_STATUS,
80 message);
81 }
82 }
83
84 }