Package ds.pjftp.command.impl

Source Code of ds.pjftp.command.impl.Mdtm

/*
* pjftp FTP server.
* Copyright (C) 2012 Dmitriy Simbiriatin <dmitriy.simbiriatin@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

package ds.pjftp.command.impl;

import ds.pjftp.utils.NotNull;

import ds.pjftp.command.Command;
import ds.pjftp.utils.DateUtils;
import ds.pjftp.main.ClientSession;

import java.io.IOException;

import java.nio.file.Path;
import java.nio.file.Files;
import java.nio.file.attribute.FileTime;

import static java.nio.file.LinkOption.NOFOLLOW_LINKS;

public class Mdtm extends Command {

    /**
     * Handles MDTM command.
     */
    @Override
    public void invoke(@NotNull final ClientSession session, @NotNull final String param) {

        final Path file = session.getFsView().getPath(param);
        if (!Files.exists(file, NOFOLLOW_LINKS)) {
            session.replyWithSpace(550, "File unavailable.");
            return;
        }

        String timestamp = null;
        try {
            final FileTime lastMod = Files.getLastModifiedTime(file, NOFOLLOW_LINKS);
            timestamp = DateUtils.format(lastMod);
        } catch (IOException ex) {
            session.replyWithSpace(500, "Failed to execute command.");
            return;
        }
        session.replyWithSpace(213, timestamp);
    }
}
TOP

Related Classes of ds.pjftp.command.impl.Mdtm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.