1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.waarp.ftp.core.command.service;
19
20 import org.waarp.common.command.ReplyCode;
21 import org.waarp.common.command.exception.CommandAbstractException;
22 import org.waarp.common.command.exception.Reply501Exception;
23 import org.waarp.common.command.exception.Reply553Exception;
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
29
30
31
32
33
34
35 public class RNTO extends AbstractCommand {
36 @Override
37 public void exec() throws CommandAbstractException {
38 if (!hasArg()) {
39 invalidCurrentCommand();
40 throw new Reply501Exception("Need a pathname as argument");
41 }
42 String filename = getArg();
43 FtpFile file = null;
44 try {
45 file = getSession().getDataConn().getFtpTransferControl()
46 .getExecutingFtpTransfer().getFtpFile();
47 } catch (FtpNoFileException e) {
48 } catch (FtpNoTransferException e) {
49 }
50 if (file != null) {
51 String previousName = file.getFile();
52 if (file.renameTo(filename)) {
53 getSession().setReplyCode(
54 ReplyCode.REPLY_250_REQUESTED_FILE_ACTION_OKAY,
55 "\"" + filename + "\" as new file name for \"" +
56 previousName + "\"");
57 return;
58 }
59 }
60
61 throw new Reply553Exception("Filename not allowed");
62 }
63
64 }