Example usage for org.apache.commons.net.ftp FTPReply COMMAND_NOT_IMPLEMENTED

List of usage examples for org.apache.commons.net.ftp FTPReply COMMAND_NOT_IMPLEMENTED

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPReply COMMAND_NOT_IMPLEMENTED.

Prototype

int COMMAND_NOT_IMPLEMENTED

To view the source code for org.apache.commons.net.ftp FTPReply COMMAND_NOT_IMPLEMENTED.

Click Source Link

Usage

From source file:com.mucommander.file.impl.ftp.FTPFile.java

/**
 * Attempts to change this file's date using the <i>'SITE UTIME'</i> FTP command.
 * This command seems to be implemeted by modern FTP servers such as ProFTPd or PureFTP Server but since it is not
 * part of the basic FTP command set, it may as well not be supported by the remote server.
 *//*  w  w w .jav  a  2 s .  c o  m*/
@Override
public void changeDate(long lastModified) throws IOException, UnsupportedFileOperationException {
    // Note: FTPFile.setTimeStamp only changes the instance's date, but doesn't change it on the server-side.
    FTPConnectionHandler connHandler = null;
    try {
        // Retrieve a ConnectionHandler and lock it
        connHandler = (FTPConnectionHandler) ConnectionPool.getConnectionHandler(this, fileURL, true);

        // Throw UnsupportedFileOperationException if we know the 'SITE UTIME' command is not supported by the server
        if (!connHandler.utimeCommandSupported)
            throw new UnsupportedFileOperationException(FileOperation.CHANGE_DATE);

        // Makes sure the connection is started, if not starts it
        connHandler.checkConnection();

        String sdate;
        // SimpleDateFormat instance must be synchronized externally if it is accessed concurrently
        synchronized (SITE_UTIME_DATE_FORMAT) {
            sdate = SITE_UTIME_DATE_FORMAT.format(new Date(lastModified));
        }

        FileLogger.finer("sending SITE UTIME " + sdate + " " + absPath);
        boolean success = connHandler.ftpClient.sendSiteCommand("UTIME " + sdate + " " + absPath);
        FileLogger.finer("server reply: " + connHandler.ftpClient.getReplyString());

        if (!success) {
            int replyCode = connHandler.ftpClient.getReplyCode();

            // If server reported that the command is not supported, mark it in the ConnectionHandler so that
            // we don't try it anymore
            if (replyCode == FTPReply.UNRECOGNIZED_COMMAND || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED
                    || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER) {

                FileLogger.fine("marking UTIME command as unsupported");
                connHandler.utimeCommandSupported = false;
            }

            throw new IOException();
        }
    } catch (IOException e) {
        // Checks if the IOException corresponds to a socket error and in that case, closes the connection
        if (connHandler != null)
            connHandler.checkSocketException(e);

        throw e;
    } finally {
        // Release the lock on the ConnectionHandler
        if (connHandler != null)
            connHandler.releaseLock();
    }
}

From source file:com.mucommander.commons.file.impl.ftp.FTPFile.java

/**
 * Attempts to change this file's date using the <i>'SITE UTIME'</i> FTP command.
 * This command seems to be implemeted by modern FTP servers such as ProFTPd or PureFTP Server but since it is not
 * part of the basic FTP command set, it may as well not be supported by the remote server.
 */// w w w .ja  v a2 s .c  o  m
@Override
public void changeDate(long lastModified) throws IOException, UnsupportedFileOperationException {
    // Note: FTPFile.setTimeStamp only changes the instance's date, but doesn't change it on the server-side.
    FTPConnectionHandler connHandler = null;
    try {
        // Retrieve a ConnectionHandler and lock it
        connHandler = (FTPConnectionHandler) ConnectionPool.getConnectionHandler(this, fileURL, true);

        // Throw UnsupportedFileOperationException if we know the 'SITE UTIME' command is not supported by the server
        if (!connHandler.utimeCommandSupported)
            throw new UnsupportedFileOperationException(FileOperation.CHANGE_DATE);

        // Makes sure the connection is started, if not starts it
        connHandler.checkConnection();

        String sdate;
        // SimpleDateFormat instance must be synchronized externally if it is accessed concurrently
        synchronized (SITE_UTIME_DATE_FORMAT) {
            sdate = SITE_UTIME_DATE_FORMAT.format(new Date(lastModified));
        }

        LOGGER.info("sending SITE UTIME {} {}", sdate, absPath);
        boolean success = connHandler.ftpClient.sendSiteCommand("UTIME " + sdate + " " + absPath);
        LOGGER.info("server reply: {}", connHandler.ftpClient.getReplyString());

        if (!success) {
            int replyCode = connHandler.ftpClient.getReplyCode();

            // If server reported that the command is not supported, mark it in the ConnectionHandler so that
            // we don't try it anymore
            if (replyCode == FTPReply.UNRECOGNIZED_COMMAND || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED
                    || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER) {

                LOGGER.info("marking UTIME command as unsupported");
                connHandler.utimeCommandSupported = false;
            }

            throw new IOException();
        }
    } catch (IOException e) {
        // Checks if the IOException corresponds to a socket error and in that case, closes the connection
        if (connHandler != null)
            connHandler.checkSocketException(e);

        throw e;
    } finally {
        // Release the lock on the ConnectionHandler
        if (connHandler != null)
            connHandler.releaseLock();
    }
}

From source file:com.mucommander.file.impl.ftp.FTPFile.java

/**
 * Changes permissions using the SITE CHMOD FTP command.
 *
 * This command is optional but seems to be supported by modern FTP servers such as ProFTPd or PureFTP Server.
 * But it may as well not be supported by the remote FTP server as it is not part of the basic FTP command set.
 *
 * Implementation note: FTPFile.setPermission only changes the instance's permissions, but doesn't change it on the
 * server-side./*from  w  w w  .  j a  v a 2  s  .  com*/
 */
@Override
public void changePermissions(int permissions) throws IOException, UnsupportedFileOperationException {
    FTPConnectionHandler connHandler = null;
    try {
        // Retrieve a ConnectionHandler and lock it
        connHandler = (FTPConnectionHandler) ConnectionPool.getConnectionHandler(this, fileURL, true);

        // Return if we know the CHMOD command is not supported by the server
        if (!connHandler.chmodCommandSupported)
            throw new UnsupportedFileOperationException(FileOperation.CHANGE_PERMISSION);

        // Makes sure the connection is started, if not starts it
        connHandler.checkConnection();

        FileLogger.finer("sending SITE CHMOD " + Integer.toOctalString(permissions) + " " + absPath);
        boolean success = connHandler.ftpClient
                .sendSiteCommand("CHMOD " + Integer.toOctalString(permissions) + " " + absPath);
        FileLogger.finer("server reply: " + connHandler.ftpClient.getReplyString());

        if (!success) {
            int replyCode = connHandler.ftpClient.getReplyCode();

            // If server reported that the command is not supported, mark it in the ConnectionHandler so that
            // we don't try it anymore
            if (replyCode == FTPReply.UNRECOGNIZED_COMMAND || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED
                    || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER) {

                FileLogger.fine("marking CHMOD command as unsupported");
                connHandler.chmodCommandSupported = false;
            }

            throw new IOException();
        }
    } catch (IOException e) {
        // Checks if the IOException corresponds to a socket error and in that case, closes the connection
        if (connHandler != null)
            connHandler.checkSocketException(e);

        throw e;
    } finally {
        // Release the lock on the ConnectionHandler
        if (connHandler != null)
            connHandler.releaseLock();
    }
}

From source file:com.mucommander.commons.file.impl.ftp.FTPFile.java

/**
 * Changes permissions using the SITE CHMOD FTP command.
 *
 * This command is optional but seems to be supported by modern FTP servers such as ProFTPd or PureFTP Server.
 * But it may as well not be supported by the remote FTP server as it is not part of the basic FTP command set.
 *
 * Implementation note: FTPFile.setPermission only changes the instance's permissions, but doesn't change it on the
 * server-side.//from  ww w. j  a va2s . c  o  m
 */
@Override
public void changePermissions(int permissions) throws IOException, UnsupportedFileOperationException {
    FTPConnectionHandler connHandler = null;
    try {
        // Retrieve a ConnectionHandler and lock it
        connHandler = (FTPConnectionHandler) ConnectionPool.getConnectionHandler(this, fileURL, true);

        // Return if we know the CHMOD command is not supported by the server
        if (!connHandler.chmodCommandSupported)
            throw new UnsupportedFileOperationException(FileOperation.CHANGE_PERMISSION);

        // Makes sure the connection is started, if not starts it
        connHandler.checkConnection();

        LOGGER.info("sending SITE CHMOD {} {}", Integer.toOctalString(permissions), absPath);
        boolean success = connHandler.ftpClient
                .sendSiteCommand("CHMOD " + Integer.toOctalString(permissions) + " " + absPath);
        LOGGER.info("server reply: {}", connHandler.ftpClient.getReplyString());

        if (!success) {
            int replyCode = connHandler.ftpClient.getReplyCode();

            // If server reported that the command is not supported, mark it in the ConnectionHandler so that
            // we don't try it anymore
            if (replyCode == FTPReply.UNRECOGNIZED_COMMAND || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED
                    || replyCode == FTPReply.COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER) {

                LOGGER.info("marking CHMOD command as unsupported");
                connHandler.chmodCommandSupported = false;
            }

            throw new IOException();
        }
    } catch (IOException e) {
        // Checks if the IOException corresponds to a socket error and in that case, closes the connection
        if (connHandler != null)
            connHandler.checkSocketException(e);

        throw e;
    } finally {
        // Release the lock on the ConnectionHandler
        if (connHandler != null)
            connHandler.releaseLock();
    }
}