chrismair | 00dc7bd | 2014-05-11 21:21:28 +0000 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright 2008 the original author or authors.
|
| 3 | *
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 | * you may not use this file except in compliance with the License.
|
| 6 | * You may obtain a copy of the License at
|
| 7 | *
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 9 | *
|
| 10 | * Unless required by applicable law or agreed to in writing, software
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 | * See the License for the specific language governing permissions and
|
| 14 | * limitations under the License.
|
| 15 | */
|
| 16 | package org.mockftpserver.fake.command;
|
| 17 |
|
| 18 | import org.mockftpserver.core.command.Command;
|
| 19 |
|
| 20 | /**
|
| 21 | * CommandHandler for the STOU command. Handler logic:
|
| 22 | * <ol>
|
| 23 | * <li>If the user has not logged in, then reply with 530 and terminate</li>
|
| 24 | * <li>Create new unique filename within the current directory</li>
|
| 25 | * <li>If the current user does not have write access to the named file, if it already exists, or else to its
|
| 26 | * parent directory, then reply with 553 and terminate</li>
|
| 27 | * <li>If the current user does not have execute access to the parent directory, then reply with 553 and terminate</li>
|
| 28 | * <li>Send an initial reply of 150</li>
|
| 29 | * <li>Read all available bytes from the data connection and write out to the unique file in the server file system</li>
|
| 30 | * <li>If file write/store fails, then reply with 553 and terminate</li>
|
| 31 | * <li>Send a final reply with 226, along with the new unique filename</li>
|
| 32 | * </ol>
|
| 33 | *
|
| 34 | * @author Chris Mair
|
| 35 | * @version $Revision$ - $Date$
|
| 36 | */
|
| 37 | public class StouCommandHandler extends AbstractStoreFileCommandHandler {
|
| 38 |
|
| 39 | /**
|
| 40 | * @return the message key for the reply message sent with the final (226) reply
|
| 41 | */
|
| 42 | protected String getMessageKey() {
|
| 43 | return "stou";
|
| 44 | }
|
| 45 |
|
| 46 | /**
|
| 47 | * Return the path (absolute or relative) for the output file.
|
| 48 | */
|
| 49 | protected String getOutputFile(Command command) {
|
| 50 | String baseName = defaultIfNullOrEmpty(command.getOptionalString(0), "Temp");
|
| 51 | String suffix = Long.toString(System.currentTimeMillis());
|
| 52 | return baseName + suffix;
|
| 53 | }
|
| 54 |
|
| 55 | } |