Package ds.pjftp.command.impl

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

/*
* 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 java.nio.file.Files;
import java.nio.file.Path;

import ds.pjftp.fs.FSView;
import ds.pjftp.command.Command;
import ds.pjftp.main.ClientSession;

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

public class Cwd extends Command {

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

        final FSView fsView = session.getFsView();
        final Path dir = fsView.getPath(param);

        if (!Files.exists(dir, NOFOLLOW_LINKS)) {
            session.replyWithSpace(550, "No such directory.");
            return;
        }
        if (!Files.isDirectory(dir, NOFOLLOW_LINKS)) {
            session.replyWithSpace(550, "Not a directory.");
            return;
        }
        fsView.changeDir(param);
        session.replyWithSpace(200, "Directory changed to {}", fsView.getWorkingDir());
    }
}
TOP

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

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.